Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,107 @@
|
|
1 |
-
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
3 |
|
4 |
-
# Load summarization
|
5 |
-
english_summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
6 |
arabic_summarizer = pipeline("summarization", model="eslamxm/mt5-base-finetuned-persian-finetuned-persian-arabic")
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
summary = english_summarizer(text, max_length=130, min_length=30, do_sample=False)
|
11 |
-
return str(summary[0]['summary_text'])
|
12 |
-
elif language == 'Arabic':
|
13 |
-
summary = arabic_summarizer(text, max_length=130, min_length=30, do_sample=False)
|
14 |
-
return str(summary[0]['summary_text'])
|
15 |
-
else:
|
16 |
-
return "Unsupported Language"
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
with gr.Column():
|
23 |
-
english_input = gr.Textbox(label="Enter English Text", placeholder="Type or paste your English text here...", lines=10)
|
24 |
-
english_button = gr.Button("Summarize English")
|
25 |
-
english_output = gr.Textbox(label="English Summary", interactive=False)
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
# Launch the interface
|
36 |
if __name__ == "__main__":
|
37 |
-
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
import time # To simulate processing time for demonstration
|
5 |
|
6 |
+
# Load the summarization pipelines
|
|
|
7 |
arabic_summarizer = pipeline("summarization", model="eslamxm/mt5-base-finetuned-persian-finetuned-persian-arabic")
|
8 |
+
english_summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
9 |
|
10 |
+
# Initialize the current language
|
11 |
+
current_language = 'Arabic'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
def summarize(text, max_length, min_length, progress=gr.Progress()):
|
14 |
+
global current_language
|
15 |
+
# Simulate a delay to show the progress bar
|
16 |
+
for step in range(10):
|
17 |
+
time.sleep(0.1) # Simulating processing time
|
18 |
+
progress(step / 10) # Update the progress bar
|
19 |
+
|
20 |
+
# Select the summarizer based on the current language
|
21 |
+
if current_language == 'Arabic':
|
22 |
+
summary = arabic_summarizer(text, max_length=max_length, min_length=min_length, do_sample=False)[0]['summary_text']
|
23 |
+
else:
|
24 |
+
summary = english_summarizer(text, max_length=max_length, min_length=min_length, do_sample=False)[0]['summary_text']
|
25 |
|
26 |
+
return summary
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
def toggle_language():
|
29 |
+
global current_language
|
30 |
+
if current_language == 'Arabic':
|
31 |
+
current_language = 'English'
|
32 |
+
return "Switched to English summarization."
|
33 |
+
else:
|
34 |
+
current_language = 'Arabic'
|
35 |
+
return "Switched to Arabic summarization."
|
36 |
+
|
37 |
+
# Custom CSS for the progress bar with animations
|
38 |
+
custom_css = """
|
39 |
+
body {
|
40 |
+
background: linear-gradient(135deg, #667eea, #764ba2);
|
41 |
+
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
42 |
+
color: #333;
|
43 |
+
margin: 0;
|
44 |
+
padding: 0;
|
45 |
+
}
|
46 |
+
.gradio-container {
|
47 |
+
background: rgba(255, 255, 255, 0.95);
|
48 |
+
border-radius: 15px;
|
49 |
+
padding: 30px 40px;
|
50 |
+
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
51 |
+
margin: 40px auto;
|
52 |
+
max-width: 1200px;
|
53 |
+
}
|
54 |
+
.gradio-container h1 {
|
55 |
+
color: #333;
|
56 |
+
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
|
57 |
+
}
|
58 |
+
.fillable {
|
59 |
+
width: 95% !important;
|
60 |
+
max-width: unset !important;
|
61 |
+
}
|
62 |
+
#examples_container {
|
63 |
+
margin: auto;
|
64 |
+
width: 90%;
|
65 |
+
}
|
66 |
+
#examples_row {
|
67 |
+
justify-content: center;
|
68 |
+
}
|
69 |
+
.sidebar {
|
70 |
+
background: rgba(255, 255, 255, 0.98);
|
71 |
+
border-radius: 10px;
|
72 |
+
padding: 20px;
|
73 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
74 |
+
}
|
75 |
+
button, .btn {
|
76 |
+
background: linear-gradient(90deg, #ff8a00, #e52e71);
|
77 |
+
border: none;
|
78 |
+
color: #fff;
|
79 |
+
padding: 12px 24px;
|
80 |
+
text-transform: uppercase;
|
81 |
+
font-weight: bold;
|
82 |
+
letter-spacing: 1px;
|
83 |
+
border-radius: 5px;
|
84 |
+
cursor: pointer;
|
85 |
+
transition: transform 0.2s ease-in-out;
|
86 |
+
}
|
87 |
+
button:hover, .btn:hover {
|
88 |
+
transform: scale(1.05);
|
89 |
+
}
|
90 |
+
"""
|
91 |
+
|
92 |
+
# Create the Gradio interface
|
93 |
+
with gr.Blocks(css=custom_css) as interface:
|
94 |
+
gr.Markdown("<h1 style='text-align: center;'>Text Summarization Tool</h1>")
|
95 |
+
|
96 |
+
text_input = gr.Textbox(label="Enter Text Here", lines=8, text_align="right")
|
97 |
+
max_length = gr.Slider(minimum=80, maximum=200, value=100, step=1, label="Max Summary Length")
|
98 |
+
min_length = gr.Slider(minimum=5, maximum=50, value=20, step=1, label="Min Summary Length")
|
99 |
+
summarize_button = gr.Button("Summarize")
|
100 |
+
language_button = gr.Button("Switch Language")
|
101 |
+
summary_output = gr.Textbox(label="Summary", lines=6, text_align="right")
|
102 |
|
103 |
+
summarize_button.click(summarize, inputs=[text_input, max_length, min_length], outputs=summary_output)
|
104 |
+
language_button.click(toggle_language, outputs=summary_output)
|
105 |
|
|
|
106 |
if __name__ == "__main__":
|
107 |
+
interface.launch()
|