File size: 1,270 Bytes
47658f6
8c9cb93
47658f6
 
 
 
 
 
 
 
8c9cb93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
import gradio as gr
from transformers import pipeline, AutoTokenizer, T5ForConditionalGeneration

# Model ve tokenizer'ı yükle
model_name = "ozcangundes/mt5-small-turkish-summarization"

def summarize_text(text):
    if len(text.split()) < 100:
        return "Metin çok kısa. En az 100 kelime olmalıdır."
    
    try:
        # Pipeline oluştur
        summarizer = pipeline(
            "summarization",
            model=model_name,
            tokenizer=model_name
        )
        
        # 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']
    except Exception as e:
        return f"Hata oluştu: {str(e)}"

# 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()