Shatha2030 commited on
Commit
98f5c51
·
verified ·
1 Parent(s): c4fb7ae

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ summarizer_en = pipeline("summarization", model="facebook/bart-large-cnn")
5
+ summarizer_ar = pipeline("translation", model="Helsinki-NLP/opus-mt-ar-en")
6
+ translator_ar = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ar")
7
+
8
+ def summarize_text(text, language):
9
+ if not text.strip():
10
+ return " الرجاء إدخال نص للتلخيص."
11
+
12
+ if language == "العربية":
13
+
14
+ translated_text = summarizer_ar(text)[0]['translation_text']
15
+ summary = summarizer_en(translated_text, min_length=10, max_length=100, do_sample=False)
16
+
17
+ final_summary = translator_ar(summary[0]['summary_text'])[0]['translation_text']
18
+ else:
19
+ summary = summarizer_en(text, min_length=10, max_length=100, do_sample=False)
20
+ final_summary = summary[0]['summary_text']
21
+
22
+ return final_summary
23
+
24
+ # Gradio
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown("# Text Summarization App")
27
+ gr.Markdown("Enter a long text below, choose the language, and get a summarized version!")
28
+
29
+ input_text = gr.Textbox(label="Input Text", placeholder="Enter your text here ^^ ...")
30
+ language = gr.Dropdown(choices=["العربية", "English"], value="English", label="Select Language")
31
+ summarize_btn = gr.Button("Summarize")
32
+ output_text = gr.Textbox(label="Summarized Text", interactive=False)
33
+
34
+ summarize_btn.click(summarize_text, inputs=[input_text, language], outputs=output_text)
35
+
36
+ if __name__ == "__main__":
37
+ demo.launch()