Spaces:
Sleeping
Sleeping
| """ | |
| HuggingFace Space Entry Point | |
| Wraps FastAPI app for Gradio/Spaces deployment | |
| """ | |
| import os | |
| import sys | |
| import asyncio | |
| # Add app to path | |
| sys.path.insert(0, os.path.dirname(__file__)) | |
| from app.main import app | |
| async def init_db(): | |
| """Initialize database tables""" | |
| try: | |
| from app.infrastructure.database.models import Base | |
| from sqlalchemy.ext.asyncio import create_async_engine | |
| database_url = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./rag_onboarding.db") | |
| # Create engine | |
| engine = create_async_engine(database_url, echo=False) | |
| # Create all tables | |
| async with engine.begin() as conn: | |
| await conn.run_sync(Base.metadata.create_all) | |
| print("✓ Database initialized") | |
| await engine.dispose() | |
| except Exception as e: | |
| print(f"! Database init warning: {e}") | |
| # Initialize DB before starting | |
| asyncio.run(init_db()) | |
| # For HF Spaces | |
| if __name__ == "__main__": | |
| import uvicorn | |
| port = int(os.getenv("PORT", 7860)) # HF Spaces default port | |
| uvicorn.run( | |
| app, | |
| host="0.0.0.0", | |
| port=port, | |
| log_level="info" | |
| ) | |