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 """
ChromaDB HF Space
✅ ChromaDB is Running!
Persistent Storage: /data/chroma_db
API Endpoint: Swagger UI (if enabled)
Direct ChromaDB API: {}/api/v1/heartbeat
""".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
# Run on port 7860 for HF Spaces UI
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860)))