Spaces:
Sleeping
Sleeping
fin09 commited on
Commit ·
f3aa3f4
1
Parent(s): 068d0d9
Mount Gradio UI onto FastAPI server to serve both / and /api/v1 endpoints
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
|
|
@@ -84,7 +84,7 @@ with gr.Blocks(title="Bilingual Arabic-English Text Summarization AI", theme=gr.
|
|
| 84 |
gr.Markdown("""
|
| 85 |
**Production NLP Platform** supporting Extractive (TextRank, LSA, Hybrid) and Abstractive (Seq2Seq + Bahdanau Attention) summarization.
|
| 86 |
|
| 87 |
-
🔗 **REST API**: Use `/api/v1/summarize` | `/api/v1/health` | `/api/v1/detect-language` | `/api/v1/evaluate`
|
| 88 |
""")
|
| 89 |
|
| 90 |
with gr.Row():
|
|
@@ -120,12 +120,13 @@ with gr.Blocks(title="Bilingual Arabic-English Text Summarization AI", theme=gr.
|
|
| 120 |
btn.click(
|
| 121 |
fn=summarize_text,
|
| 122 |
inputs=[input_text, algorithm, sentences, beam_width],
|
| 123 |
-
outputs=[output_summary, out_lang, out_reduc, out_lat]
|
|
|
|
| 124 |
)
|
| 125 |
|
| 126 |
-
#
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
| 1 |
"""
|
| 2 |
+
Main entry point for Hugging Face Spaces (Gradio SDK + FastAPI REST API).
|
| 3 |
+
Mounts Gradio UI onto FastAPI server so that both the Web UI (at /) and REST API (at /api/v1/...) work seamlessly.
|
| 4 |
"""
|
| 5 |
|
| 6 |
import os
|
|
|
|
| 84 |
gr.Markdown("""
|
| 85 |
**Production NLP Platform** supporting Extractive (TextRank, LSA, Hybrid) and Abstractive (Seq2Seq + Bahdanau Attention) summarization.
|
| 86 |
|
| 87 |
+
🔗 **REST API**: Use `/api/v1/summarize` | `/api/v1/health` | `/api/v1/detect-language` | `/api/v1/evaluate` | Docs at `/docs`
|
| 88 |
""")
|
| 89 |
|
| 90 |
with gr.Row():
|
|
|
|
| 120 |
btn.click(
|
| 121 |
fn=summarize_text,
|
| 122 |
inputs=[input_text, algorithm, sentences, beam_width],
|
| 123 |
+
outputs=[output_summary, out_lang, out_reduc, out_lat],
|
| 124 |
+
api_name="summarize"
|
| 125 |
)
|
| 126 |
|
| 127 |
+
# Mount Gradio UI directly onto the FastAPI app
|
| 128 |
+
app = gr.mount_gradio_app(fastapi_app, demo, path="/")
|
| 129 |
|
| 130 |
+
if __name__ == "__main__":
|
| 131 |
+
import uvicorn
|
| 132 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|