Spaces:
Sleeping
Sleeping
| # app.py | |
| import os | |
| from fastapi import FastAPI | |
| import gradio as gr | |
| from gradio.routes import mount_gradio_app | |
| from src.gradio.app import build_app | |
| # Désactiver le SSR de Gradio (pas nécessaire sur Spaces pour nous) | |
| os.environ["GRADIO_SSR_MODE"] = "false" | |
| print("new /") | |
| # 1) Créer l'app FastAPI "parent" | |
| fastapi_app = FastAPI() | |
| # 2) Construire l'app Gradio | |
| demo = build_app() | |
| demo.queue() # queue activée, comme d’habitude | |
| # 3) Monter Gradio sur la FastAPI | |
| app = mount_gradio_app( | |
| fastapi_app, | |
| demo, | |
| path="/", # Gradio servi à la racine | |
| ) | |
| print("new / (app mounted OK)") | |
| # 4) Lancer uvicorn quand le script est exécuté directement | |
| if __name__ == "__main__": | |
| import uvicorn | |
| port = int(os.getenv("PORT", "7860")) | |
| print(f"🚀 Starting uvicorn on 0.0.0.0:{port}") | |
| uvicorn.run(app, host="0.0.0.0", port=port) | |