Spaces:
Running
Running
Upload 2 files
Browse files- app.py +33 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqGeneration
|
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 |
+
# Metni özetle
|
15 |
+
summary = summarizer(text,
|
16 |
+
max_length=150,
|
17 |
+
min_length=50,
|
18 |
+
length_penalty=2.0,
|
19 |
+
num_beams=4,
|
20 |
+
early_stopping=True)
|
21 |
+
|
22 |
+
return summary[0]['summary_text']
|
23 |
+
|
24 |
+
# Gradio arayüzünü oluştur
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=summarize_text,
|
27 |
+
inputs=gr.Textbox(lines=10, label="Özetlenecek Metin"),
|
28 |
+
outputs=gr.Textbox(label="Özet"),
|
29 |
+
title="Türkçe Metin Özetleme",
|
30 |
+
description="Türkçe metinleri özetleyen yapay zeka modeli. En az 100 kelimelik metin giriniz."
|
31 |
+
)
|
32 |
+
|
33 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio>=3.50.2
|
2 |
+
transformers>=4.30.0
|
3 |
+
torch>=2.0.0
|
4 |
+
sentencepiece>=0.1.99
|