Spaces:
Sleeping
Sleeping
File size: 1,625 Bytes
6b89276 |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
# ุชููุฆุฉ ุงููู
ูุฐุฌ
model = AutoModelForSeq2SeqLM.from_pretrained("methodya/arabic-summarizer-philosophy")
tokenizer = AutoTokenizer.from_pretrained("methodya/arabic-summarizer-philosophy")
def summarize(text, max_length=150, num_beams=7, length_penalty=0.8):
# ุชุญููู ุงูููู
ุฅูู ุงูููุน ุงูู
ูุงุณุจ
max_length = int(max_length)
num_beams = int(num_beams)
length_penalty = float(length_penalty)
# ุชุฌููุฒ ุงูุจูุงูุงุช ูููู
ูุฐุฌ
inputs = tokenizer(text, return_tensors="pt", max_length=2048, truncation=True)
outputs = model.generate(
**inputs,
max_length=max_length,
num_beams=num_beams,
length_penalty=length_penalty,
early_stopping=True
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
css = """
.gradio-container {background: #f9fafb !important}
.rtl-text {
direction: rtl;
text-align: right;
font-family: Arial, sans-serif;
}
"""
interface = gr.Interface(
fn=summarize,
inputs=[
gr.Textbox(lines=8, label="ุงููุต", elem_classes="rtl-text"),
gr.Slider(50, 250, value=150, label="ุทูู ุงูู
ูุฎุต"),
gr.Slider(1, 10, value=7, step=1, label="ุฏูุฉ ุงูุชูุฎูุต (num_beams)"),
gr.Slider(0.1, 2.0, value=0.8, step=0.1, label="ู
ุนุงู
ู ุงูุทูู")
],
outputs=gr.Textbox(label="ุงูู
ูุฎุต", elem_classes="rtl-text"),
title="ู
ูุฎุต ุงููุตูุต ุงูููุณููุฉ",
theme=gr.themes.Soft(),
css=css
)
interface.launch() |