File size: 1,194 Bytes
3b2c787
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained("ahmedabdo/arabic-summarizer-bart")
model = AutoModelForSeq2SeqLM.from_pretrained("ahmedabdo/arabic-summarizer-bart")

def summarize_text(text):
    if not text.strip():
        return "Please enter some text to summarize."
    inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
    summary_ids = model.generate(inputs["input_ids"], min_length=10, max_length=100, length_penalty=2.0, num_beams=4, early_stopping=True)
    summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
    return summary

# Define the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# تلخيص النصوص باستخدام نموذج BART")
    
    with gr.Row():
        input_text = gr.Textbox(label="أدخل النص", placeholder="ضع النص هنا", lines=10)
    
    summarize_button = gr.Button("أبدا التلخيص")
    
    output_text = gr.Textbox(label="تلخيص النص", interactive=False)
    
    summarize_button.click(summarize_text, inputs=input_text, outputs=output_text)

# Launch the app
demo.launch()