Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app.py +24 -0
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -4,12 +4,36 @@ Wraps FastAPI app for Gradio/Spaces deployment
|
|
| 4 |
"""
|
| 5 |
import os
|
| 6 |
import sys
|
|
|
|
| 7 |
|
| 8 |
# Add app to path
|
| 9 |
sys.path.insert(0, os.path.dirname(__file__))
|
| 10 |
|
| 11 |
from app.main import app
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# For HF Spaces
|
| 14 |
if __name__ == "__main__":
|
| 15 |
import uvicorn
|
|
|
|
| 4 |
"""
|
| 5 |
import os
|
| 6 |
import sys
|
| 7 |
+
import asyncio
|
| 8 |
|
| 9 |
# Add app to path
|
| 10 |
sys.path.insert(0, os.path.dirname(__file__))
|
| 11 |
|
| 12 |
from app.main import app
|
| 13 |
|
| 14 |
+
async def init_db():
|
| 15 |
+
"""Initialize database tables"""
|
| 16 |
+
try:
|
| 17 |
+
from app.infrastructure.database.models import Base
|
| 18 |
+
from sqlalchemy.ext.asyncio import create_async_engine
|
| 19 |
+
|
| 20 |
+
database_url = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./rag_onboarding.db")
|
| 21 |
+
|
| 22 |
+
# Create engine
|
| 23 |
+
engine = create_async_engine(database_url, echo=False)
|
| 24 |
+
|
| 25 |
+
# Create all tables
|
| 26 |
+
async with engine.begin() as conn:
|
| 27 |
+
await conn.run_sync(Base.metadata.create_all)
|
| 28 |
+
|
| 29 |
+
print("✓ Database initialized")
|
| 30 |
+
await engine.dispose()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"! Database init warning: {e}")
|
| 33 |
+
|
| 34 |
+
# Initialize DB before starting
|
| 35 |
+
asyncio.run(init_db())
|
| 36 |
+
|
| 37 |
# For HF Spaces
|
| 38 |
if __name__ == "__main__":
|
| 39 |
import uvicorn
|
requirements.txt
CHANGED
|
@@ -4,6 +4,7 @@ pydantic==2.5.3
|
|
| 4 |
pydantic-settings==2.1.0
|
| 5 |
sqlalchemy==2.0.25
|
| 6 |
asyncpg==0.29.0
|
|
|
|
| 7 |
redis[hiredis]==5.0.1
|
| 8 |
qdrant-client==1.7.3
|
| 9 |
sentence-transformers==2.3.1
|
|
@@ -16,4 +17,3 @@ tenacity==8.2.3
|
|
| 16 |
httpx==0.26.0
|
| 17 |
python-multipart==0.0.6
|
| 18 |
aiofiles==23.2.1
|
| 19 |
-
psycopg2-binary==2.9.9
|
|
|
|
| 4 |
pydantic-settings==2.1.0
|
| 5 |
sqlalchemy==2.0.25
|
| 6 |
asyncpg==0.29.0
|
| 7 |
+
aiosqlite==0.19.0
|
| 8 |
redis[hiredis]==5.0.1
|
| 9 |
qdrant-client==1.7.3
|
| 10 |
sentence-transformers==2.3.1
|
|
|
|
| 17 |
httpx==0.26.0
|
| 18 |
python-multipart==0.0.6
|
| 19 |
aiofiles==23.2.1
|
|
|