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