File size: 890 Bytes
9f4b1f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()