fin09 commited on
Commit
c54fc68
·
1 Parent(s): 043f08c

Use native demo.launch() with FastAPI routes for HuggingFace Spaces lifecycle

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -1,6 +1,6 @@
1
  """
2
  Main entry point for Hugging Face Spaces (Gradio SDK).
3
- Mounts the production FastAPI REST API and provides an interactive Gradio Web UI simultaneously.
4
  """
5
 
6
  import os
@@ -71,7 +71,7 @@ with gr.Blocks(title="Bilingual Arabic-English Text Summarization AI", theme=gr.
71
  gr.Markdown("""
72
  **Production NLP Platform** supporting Extractive (TextRank, LSA, Hybrid) and Abstractive (Seq2Seq + Bahdanau Attention) summarization.
73
 
74
- 🔗 **REST API Documentation**: Access Swagger UI at `[URL]/docs` | ReDoc at `[URL]/redoc`
75
  """)
76
 
77
  with gr.Row():
@@ -110,9 +110,11 @@ with gr.Blocks(title="Bilingual Arabic-English Text Summarization AI", theme=gr.
110
  outputs=[output_summary, out_lang, out_reduc, out_lat]
111
  )
112
 
113
- # Mount Gradio onto FastAPI so both work simultaneously!
114
- app = gr.mount_gradio_app(fastapi_app, demo, path="/")
 
 
115
 
116
- if __name__ == "__main__":
117
- import uvicorn
118
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
  """
2
  Main entry point for Hugging Face Spaces (Gradio SDK).
3
+ Provides an interactive Gradio Web UI and exposes the FastAPI REST API simultaneously.
4
  """
5
 
6
  import os
 
71
  gr.Markdown("""
72
  **Production NLP Platform** supporting Extractive (TextRank, LSA, Hybrid) and Abstractive (Seq2Seq + Bahdanau Attention) summarization.
73
 
74
+ 🔗 **API Endpoints**: `/api/v1/summarize` | `/api/v1/health` | `/api/v1/detect-language` | `/api/v1/evaluate`
75
  """)
76
 
77
  with gr.Row():
 
110
  outputs=[output_summary, out_lang, out_reduc, out_lat]
111
  )
112
 
113
+ # Attach FastAPI endpoints directly into Gradio's internal FastAPI app
114
+ for route in fastapi_app.routes:
115
+ if hasattr(route, "path") and route.path.startswith("/api/"):
116
+ demo.app.routes.append(route)
117
 
118
+ # Launch Gradio app directly (required for Hugging Face Spaces lifecycle)
119
+ demo.queue()
120
+ demo.launch(server_name="0.0.0.0", server_port=7860)