Spaces:
Build error
Build error
| 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() |