Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
|
|
|
4 |
model_id = "methodya/arabic-summarizer-philosophy"
|
5 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
7 |
|
8 |
-
|
|
|
9 |
inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
|
10 |
-
outputs = model.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
12 |
|
|
|
13 |
interface = gr.Interface(
|
14 |
fn=summarize,
|
15 |
inputs=[
|
16 |
-
gr.Textbox(lines=8, label="النص"),
|
17 |
-
gr.Slider(50, 250, value=150, label="طول الملخص")
|
|
|
|
|
18 |
],
|
19 |
-
outputs=gr.Textbox(label="الملخص"),
|
20 |
title="ملخص النصوص الفلسفية",
|
21 |
-
description="نموذج لتلخيص النصوص الفلسفية باللغة العربية"
|
22 |
)
|
23 |
|
24 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
|
4 |
+
# تحميل النموذج والتوكنايزر
|
5 |
model_id = "methodya/arabic-summarizer-philosophy"
|
6 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
8 |
|
9 |
+
# دالة التلخيص مع المعاملات الجديدة
|
10 |
+
def summarize(text, max_length=150, num_beams=7, length_penalty=0.8):
|
11 |
inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
|
12 |
+
outputs = model.generate(
|
13 |
+
**inputs,
|
14 |
+
max_length=max_length,
|
15 |
+
num_beams=num_beams,
|
16 |
+
length_penalty=length_penalty,
|
17 |
+
early_stopping=True
|
18 |
+
)
|
19 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
|
21 |
+
# إعداد واجهة Gradio
|
22 |
interface = gr.Interface(
|
23 |
fn=summarize,
|
24 |
inputs=[
|
25 |
+
gr.Textbox(lines=8, label="النص"), # النص الأصلي
|
26 |
+
gr.Slider(50, 250, value=150, label="طول الملخص"), # max_length
|
27 |
+
gr.Slider(1, 10, value=7, step=1, label="دقة التلخيص (num_beams)"), # num_beams
|
28 |
+
gr.Slider(0.1, 2.0, value=0.8, step=0.1, label="معامل الطول (length_penalty)") # length_penalty
|
29 |
],
|
30 |
+
outputs=gr.Textbox(label="الملخص"), # النص الملخص
|
31 |
title="ملخص النصوص الفلسفية",
|
32 |
+
description="نموذج لتلخيص النصوص الفلسفية باللغة العربية مع إعدادات متقدمة"
|
33 |
)
|
34 |
|
35 |
+
# تشغيل التطبيق
|
36 |
+
interface.launch()
|