""" Hugging Face Spaces entry point for HackRx 6.0 This file is specifically for Hugging Face Spaces deployment """ import os import sys from pathlib import Path # Add the current directory to Python path sys.path.append(str(Path(__file__).parent)) # Set environment variables for Hugging Face cache os.environ.setdefault("HF_HOME", "/code/.cache/huggingface") os.environ.setdefault("TRANSFORMERS_CACHE", "/code/.cache/huggingface") os.environ.setdefault("HF_HUB_CACHE", "/code/.cache/huggingface") # Create cache directory if it doesn't exist cache_dir = "/code/.cache/huggingface" try: os.makedirs(cache_dir, exist_ok=True) except Exception as e: print(f"Warning: Could not create cache directory: {e}") # Import the main app and initialize services try: from main import app as main_app, lifespan from main import get_query_service, process_query, process_query_legacy, process_query_detailed, analyze_document, summarize_document print("โœ… Successfully imported main.py app and services") # Use the main app directly app = main_app print("โœ… Using main.py app with proper service initialization") except Exception as e: print(f"โŒ Failed to import main.py app: {e}") print("Creating fallback app...") # Create fallback app from fastapi import FastAPI, Request app = FastAPI( title="HackRx 6.0 - Intelligent Query-Retrieval System", description="LLM-Powered Intelligent Query-Retrieval System for HackRx 6.0", version="1.0.0" ) # Add middleware to log all requests @app.middleware("http") async def log_requests(request: Request, call_next): print(f"๐Ÿ” Request: {request.method} {request.url.path}") response = await call_next(request) print(f"๐Ÿ“ค Response: {response.status_code}") return response # Add guaranteed working endpoints @app.get("/") async def root(): print("๐ŸŽฏ Root endpoint called") return { "message": "HackRx 6.0 - Intelligent Query-Retrieval System", "version": "1.0.0", "status": "fallback_mode", "note": "App is running in fallback mode due to initialization issues", "error": str(e), "endpoints": { "main": "api/v1/hackrx/run", "legacy": "hackrx/run", "detailed": "api/v1/hackrx/run/detailed", "health": "health", "docs": "docs", "test": "test" } } @app.get("/health") async def health_check(): print("๐Ÿฅ Health endpoint called") return { "status": "fallback", "message": "App is running in fallback mode", "services": { "query_service": False, "embedding_service": False, "llm_service": False, "pinecone_service": False }, "error": str(e) } @app.get("/test") async def test_endpoint(): print("๐Ÿงช Test endpoint called") return { "message": "Test endpoint working!", "status": "success", "app_loaded": False, "mode": "fallback", "error": str(e) } # For Hugging Face Spaces, we need to expose the app directly if __name__ == "__main__": import uvicorn print("๐Ÿš€ Starting HackRx 6.0 on Hugging Face Spaces...") uvicorn.run(app, host="0.0.0.0", port=7860)