Spaces:
Running
Running
Upload 2 files
Browse files- app.py +24 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
def summarize(text, max_length=150):
|
9 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
|
10 |
+
outputs = model.generate(**inputs, max_length=max_length)
|
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 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio>=3.50.0
|
2 |
+
torch
|
3 |
+
transformers
|