ai-lab / main.py
ClemSummer's picture
fix: set app_port to 7860 to match Docker CMD
54c9e50
raw
history blame
884 Bytes
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import uvicorn
from vit_captioning.generate import CaptionGenerator
app = FastAPI()
caption_generator = None # Lazy-load placeholder
@app.on_event("startup")
def startup_event():
global caption_generator
if caption_generator is None:
print("Loading CaptionGenerator...")
caption_generator = CaptionGenerator()
@app.get("/", response_class=HTMLResponse)
def root():
return "<h3>βœ… Hugging Face Space is alive</h3>"
@app.get("/health")
def health_check():
return {"status": "ok"}
# Example endpoint to trigger model
@app.get("/caption")
def caption():
if caption_generator is None:
return {"error": "Model not loaded"}
return {"result": "dummy caption"} # Replace with real logic
# if __name__ == "__main__":
# uvicorn.run(app, host="0.0.0.0", port=8000)