Kaaado's picture
fix: move spaces import to top of app.py and trigger startup_report directly
4dd9774
Raw History Blame Contribute Delete
2.09 kB
# HF ZeroGPU compatibility declaration (must be top of file)
try:
import spaces
@spaces.GPU(duration=1)
def _hf_spaces_gpu_worker():
return True
# Report to ZeroGPU supervisor that decorated functions are registered
try:
from spaces.zero import client as _zero_client
_zero_client.startup_report()
except Exception:
pass
except Exception:
_hf_spaces_gpu_worker = None
import os
import uvicorn
import gradio as gr
# Set runtime model paths
os.environ["YOLO_FAST_MODEL"] = "data/yolo/yolov8_optimized_mobile_int8.tflite"
os.environ["YOLO_BALANCED_MODEL"] = "data/yolo/yolov8_standard_mobile_fp16.tflite"
os.environ["YOLO_HEAVY_MODEL"] = "data/yolo/yolov8_high_res_web_fp32.tflite"
os.environ["YOLO_LIMITED_MODEL"] = "data/yolo/yolov8s_limited.onnx"
os.environ["YOLO_ONNX_MODEL"] = "data/yolo/yolov8_mobile_web.onnx"
os.environ["CNN_MODEL"] = "data/cnn/cnn_server_fp32.onnx"
os.environ["CNN_INT8_MODEL"] = "data/cnn/cnn_server_int8.onnx"
os.environ["CNN_LIMITED_MODEL"] = "data/cnn/cnn_limited.onnx"
os.environ["ENABLE_YOLO"] = "true"
os.environ["ENABLE_CNN"] = "true"
os.environ["ENABLE_FUSION"] = "true"
# 1. Import production FastAPI app
from app.main import app as fastapi_app
# 2. Create status UI
with gr.Blocks(title="Agrovia Production Detection Service") as demo:
gr.Markdown("# 🌱 Agrovia Full AI Inference Microservice")
gr.Markdown("Production REST API endpoints active:")
gr.Markdown("- **POST** `/api/v1/analyze` — Full YOLO + CNN + Decision Fusion")
gr.Markdown("- **POST** `/api/v1/classify` — CNN Classification")
gr.Markdown("- **POST** `/api/v1/detect` — YOLO Detection")
gr.Markdown("- **GET** `/api/v1/health` — System Health & Readiness")
if _hf_spaces_gpu_worker is not None:
_dummy_btn = gr.Button("GPU Check", visible=False)
_dummy_btn.click(fn=_hf_spaces_gpu_worker, inputs=[], outputs=[])
# 3. Mount Gradio to /
app = gr.mount_gradio_app(fastapi_app, demo, path="/")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7860)