Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +20 -13
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,25 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline, AutoTokenizer,
|
| 3 |
|
| 4 |
# Model ve tokenizer'ı yükle
|
| 5 |
model_name = "ozcangundes/mt5-small-turkish-summarization"
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
-
model = AutoModelForSeq2SeqGeneration.from_pretrained(model_name)
|
| 8 |
-
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
|
| 9 |
|
| 10 |
def summarize_text(text):
|
| 11 |
if len(text.split()) < 100:
|
| 12 |
return "Metin çok kısa. En az 100 kelime olmalıdır."
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Gradio arayüzünü oluştur
|
| 25 |
iface = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, AutoTokenizer, T5ForConditionalGeneration
|
| 3 |
|
| 4 |
# Model ve tokenizer'ı yükle
|
| 5 |
model_name = "ozcangundes/mt5-small-turkish-summarization"
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def summarize_text(text):
|
| 8 |
if len(text.split()) < 100:
|
| 9 |
return "Metin çok kısa. En az 100 kelime olmalıdır."
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
# Pipeline oluştur
|
| 13 |
+
summarizer = pipeline(
|
| 14 |
+
"summarization",
|
| 15 |
+
model=model_name,
|
| 16 |
+
tokenizer=model_name
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Metni özetle
|
| 20 |
+
summary = summarizer(text,
|
| 21 |
+
max_length=150,
|
| 22 |
+
min_length=50,
|
| 23 |
+
length_penalty=2.0,
|
| 24 |
+
num_beams=4,
|
| 25 |
+
early_stopping=True)
|
| 26 |
+
|
| 27 |
+
return summary[0]['summary_text']
|
| 28 |
+
except Exception as e:
|
| 29 |
+
return f"Hata oluştu: {str(e)}"
|
| 30 |
|
| 31 |
# Gradio arayüzünü oluştur
|
| 32 |
iface = gr.Interface(
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
gradio>=3.50.2
|
| 2 |
transformers>=4.30.0
|
| 3 |
torch>=2.0.0
|
| 4 |
-
sentencepiece>=0.1.99
|
|
|
|
|
|
| 1 |
gradio>=3.50.2
|
| 2 |
transformers>=4.30.0
|
| 3 |
torch>=2.0.0
|
| 4 |
+
sentencepiece>=0.1.99
|
| 5 |
+
protobuf>=3.20.0
|