| import os |
| import requests |
| from fastapi import FastAPI |
| from fastapi.responses import HTMLResponse |
|
|
| app = FastAPI(title="ChromaDB on HF Space") |
|
|
| CHROMA_URL = "http://localhost:8000" |
|
|
| @app.get("/", response_class=HTMLResponse) |
| def read_root(): |
| return """ |
| <html> |
| <head><title>ChromaDB HF Space</title></head> |
| <body> |
| <h1>✅ ChromaDB is Running!</h1> |
| <p>Persistent Storage: /data/chroma_db</p> |
| <p>API Endpoint: <a href="/docs">Swagger UI</a> (if enabled)</p> |
| <p>Direct ChromaDB API: <code>{}/api/v1/heartbeat</code></p> |
| </body> |
| </html> |
| """.format(CHROMA_URL) |
|
|
| @app.get("/health") |
| def health_check(): |
| try: |
| response = requests.get(f"{CHROMA_URL}/api/v1/heartbeat") |
| if response.status_code == 200: |
| return {"status": "healthy", "chromadb": "up"} |
| else: |
| return {"status": "unhealthy", "chromadb": "error"} |
| except Exception as e: |
| return {"status": "error", "detail": str(e)} |
|
|
| if __name__ == "__main__": |
| import uvicorn |
| |
| uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860))) |