File size: 1,181 Bytes
47658f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqGeneration

# Model ve tokenizer'ı yükle
model_name = "ozcangundes/mt5-small-turkish-summarization"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqGeneration.from_pretrained(model_name)
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)

def summarize_text(text):
    if len(text.split()) < 100:
        return "Metin çok kısa. En az 100 kelime olmalıdır."
    
    # Metni özetle
    summary = summarizer(text, 
                        max_length=150, 
                        min_length=50, 
                        length_penalty=2.0,
                        num_beams=4,
                        early_stopping=True)
    
    return summary[0]['summary_text']

# Gradio arayüzünü oluştur
iface = gr.Interface(
    fn=summarize_text,
    inputs=gr.Textbox(lines=10, label="Özetlenecek Metin"),
    outputs=gr.Textbox(label="Özet"),
    title="Türkçe Metin Özetleme",
    description="Türkçe metinleri özetleyen yapay zeka modeli. En az 100 kelimelik metin giriniz."
)

iface.launch()