Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,27 @@ def toggle_language():
|
|
| 32 |
return "Switched to English summarization."
|
| 33 |
else:
|
| 34 |
current_language = 'Arabic'
|
| 35 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Custom CSS for the progress bar with animations
|
| 38 |
custom_css = """
|
|
@@ -91,17 +111,32 @@ button:hover, .btn:hover {
|
|
| 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 |
-
|
| 97 |
-
|
| 98 |
-
|
| 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()
|
|
|
|
| 32 |
return "Switched to English summarization."
|
| 33 |
else:
|
| 34 |
current_language = 'Arabic'
|
| 35 |
+
return "تم التبديل إلى تلخيص اللغة العربية."
|
| 36 |
+
|
| 37 |
+
def update_interface():
|
| 38 |
+
if current_language == 'Arabic':
|
| 39 |
+
return {
|
| 40 |
+
"title": "أداة تلخيص النصوص",
|
| 41 |
+
"textbox_label": "ادخل النص هنا",
|
| 42 |
+
"max_length_label": "الحد الأقصى لطول الملخص",
|
| 43 |
+
"min_length_label": "الحد الأدنى لطول الملخص",
|
| 44 |
+
"summarize_button_label": "تلخيص",
|
| 45 |
+
"summary_label": "الملخص"
|
| 46 |
+
}
|
| 47 |
+
else:
|
| 48 |
+
return {
|
| 49 |
+
"title": "Text Summarization Tool",
|
| 50 |
+
"textbox_label": "Enter Text Here",
|
| 51 |
+
"max_length_label": "Max Summary Length",
|
| 52 |
+
"min_length_label": "Min Summary Length",
|
| 53 |
+
"summarize_button_label": "Summarize",
|
| 54 |
+
"summary_label": "Summary"
|
| 55 |
+
}
|
| 56 |
|
| 57 |
# Custom CSS for the progress bar with animations
|
| 58 |
custom_css = """
|
|
|
|
| 111 |
|
| 112 |
# Create the Gradio interface
|
| 113 |
with gr.Blocks(css=custom_css) as interface:
|
| 114 |
+
gr.Markdown("<h1 style='text-align: center;' id='title'>Text Summarization Tool</h1>")
|
| 115 |
+
|
| 116 |
+
text_input = gr.Textbox(label="Enter Text Here", lines=8, text_align="right", elem_id="text_input")
|
| 117 |
+
max_length = gr.Slider(minimum=80, maximum=200, value=100, step=1, label="Max Summary Length", elem_id="max_length")
|
| 118 |
+
min_length = gr.Slider(minimum=5, maximum=50, value=20, step=1, label="Min Summary Length", elem_id="min_length")
|
| 119 |
|
| 120 |
+
summarize_button = gr.Button("Summarize", elem_id="summarize_button")
|
| 121 |
+
language_button = gr.Button("Switch Language", elem_id="language_button")
|
| 122 |
+
summary_output = gr.Textbox(label="Summary", lines=6, text_align="right", elem_id="summary_output")
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
summarize_button.click(summarize, inputs=[text_input, max_length, min_length], outputs=summary_output)
|
| 125 |
+
language_button.click(lambda: (toggle_language(), update_interface()), outputs=[summary_output, text_input, max_length, min_length, summarize_button, language_button])
|
| 126 |
+
|
| 127 |
+
# Update interface labels
|
| 128 |
+
def update_labels():
|
| 129 |
+
labels = update_interface()
|
| 130 |
+
return labels["title"], labels["textbox_label"], labels["max_length_label"], labels["min_length_label"], labels["summarize_button_label"], labels["summary_label"]
|
| 131 |
+
|
| 132 |
+
title, text_label, max_label, min_label, summarize_label, summary_label = update_labels()
|
| 133 |
+
|
| 134 |
+
interface.set_title(title)
|
| 135 |
+
text_input.label = text_label
|
| 136 |
+
max_length.label = max_label
|
| 137 |
+
min_length.label = min_label
|
| 138 |
+
summarize_button.label = summarize_label
|
| 139 |
+
summary_output.label = summary_label
|
| 140 |
|
| 141 |
if __name__ == "__main__":
|
| 142 |
interface.launch()
|