Spaces:
Sleeping
Sleeping
fin09 commited on
Commit ·
c54fc68
1
Parent(s): 043f08c
Use native demo.launch() with FastAPI routes for HuggingFace Spaces lifecycle
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Main entry point for Hugging Face Spaces (Gradio SDK).
|
| 3 |
-
|
| 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 |
-
🔗 **
|
| 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 |
-
#
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
| 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)
|