Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load summarization models
|
6 |
+
english_summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
7 |
+
arabic_summarizer = pipeline("summarization", model="google/mt5-small")
|
8 |
+
|
9 |
+
def summarize_text(text, language):
|
10 |
+
if language == 'English':
|
11 |
+
summary = english_summarizer(text, max_length=130, min_length=30, do_sample=False)
|
12 |
+
return summary[0]['summary_text']
|
13 |
+
elif language == 'Arabic':
|
14 |
+
summary = arabic_summarizer(text, max_length=130, min_length=30, do_sample=False)
|
15 |
+
return summary[0]['summary_text']
|
16 |
+
else:
|
17 |
+
return "Unsupported Language"
|
18 |
+
|
19 |
+
with gr.Blocks() as app:
|
20 |
+
gr.Markdown("<h1 style='text-align: center;'>Text Summarization App</h1>")
|
21 |
+
|
22 |
+
with gr.Row():
|
23 |
+
with gr.Column():
|
24 |
+
english_input = gr.Textbox(label="Enter English Text", placeholder="Type or paste your English text here...", lines=10)
|
25 |
+
english_button = gr.Button("Summarize English")
|
26 |
+
english_output = gr.Textbox(label="English Summary", interactive=False)
|
27 |
+
|
28 |
+
with gr.Column():
|
29 |
+
arabic_input = gr.Textbox(label="ادخل نص عربي", placeholder="اكتب أو الصق نصك العربي هنا...", lines=10)
|
30 |
+
arabic_button = gr.Button("تلخيص عربي")
|
31 |
+
arabic_output = gr.Textbox(label="ملخص عربي", interactive=False)
|
32 |
+
|
33 |
+
english_button.click(summarize_text, inputs=[english_input, 'English'], outputs=english_output)
|
34 |
+
arabic_button.click(summarize_text, inputs=[arabic_input, 'Arabic'], outputs=arabic_output)
|
35 |
+
|
36 |
+
# Launch the interface
|
37 |
+
if __name__ == "__main__":
|
38 |
+
app.launch()
|