Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
# Load model directly
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 4 |
+
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("ahmedabdo/arabic-summarizer-bart")
|
| 6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("ahmedabdo/arabic-summarizer-bart")
|
| 7 |
+
|
| 8 |
+
def summarize_text(text, min_length, max_length):
|
| 9 |
+
if not text.strip():
|
| 10 |
+
return "Please enter some text to summarize."
|
| 11 |
+
summary = summarizer(text, min_length=min_length, max_length=max_length, truncation=True)
|
| 12 |
+
return summary[0]["summary_text"]
|
| 13 |
+
|
| 14 |
+
# Define the Gradio interface
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("# تلخيص النصوص باستخدام نموذج BART")
|
| 17 |
+
|
| 18 |
+
with gr.Row():
|
| 19 |
+
input_text = gr.Textbox(label="أدخل النص", placeholder="ضع النص هنا", lines=10)
|
| 20 |
+
|
| 21 |
+
min_length_slider = gr.Slider(10, 50, value=10, step=1, label="Minimum Summary Length (tokens)")
|
| 22 |
+
max_length_slider = gr.Slider(50, 150, value=100, step=1, label="Maximum Summary Length (tokens)")
|
| 23 |
+
|
| 24 |
+
summarize_button = gr.Button("أبدا التلخيص")
|
| 25 |
+
|
| 26 |
+
output_text = gr.Textbox(label="تلخيص النص", interactive=False)
|
| 27 |
+
|
| 28 |
+
summarize_button.click(summarize_text, inputs=[input_text, min_length_slider, max_length_slider], outputs=output_text)
|
| 29 |
+
|
| 30 |
+
# Launch the app
|
| 31 |
+
demo.launch()
|