|
import gradio as gr |
|
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer |
|
|
|
model_id = "methodya/arabic-summarizer-philosophy" |
|
model = AutoModelForSeq2SeqLM.from_pretrained(model_id) |
|
tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
|
|
def summarize(text, max_length=150): |
|
inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True) |
|
outputs = model.generate(**inputs, max_length=max_length) |
|
return tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
interface = gr.Interface( |
|
fn=summarize, |
|
inputs=[ |
|
gr.Textbox(lines=8, label="النص"), |
|
gr.Slider(50, 250, value=150, label="طول الملخص") |
|
], |
|
outputs=gr.Textbox(label="الملخص"), |
|
title="ملخص النصوص الفلسفية", |
|
description="نموذج لتلخيص النصوص الفلسفية باللغة العربية" |
|
) |
|
|
|
interface.launch() |