File size: 1,154 Bytes
256649d
 
 
da2abdc
c147591
 
 
 
 
 
 
 
 
 
 
 
256649d
c147591
 
 
 
 
 
da2abdc
ef03384
da2abdc
c147591
 
 
da2abdc
c147591
 
ef03384
da2abdc
 
 
 
 
 
c147591
da2abdc
c147591
 
 
 
 
 
ef03384
c147591
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
41
42
43
44
45
46
47
48
49
50
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline

# Modeli tek sefer yükle
model = AutoModelForSequenceClassification.from_pretrained(
    "savasy/bert-base-turkish-sentiment-cased"
)
tokenizer = AutoTokenizer.from_pretrained(
    "savasy/bert-base-turkish-sentiment-cased"
)

sentiment_pipe = pipeline(
    "sentiment-analysis",
    tokenizer=tokenizer,
    model=model
)

def analyze(text):
    result = sentiment_pipe(text)[0]["label"]
    if result == "positive":
        return "🔵 POZİTİF"
    elif result == "negative":
        return "🔴 NEGATİF"
    return "🟡 NÖTR"

with gr.Blocks() as demo:
    gr.Markdown(
        """
        # 🇹🇷 Türkçe Duygu Analizi  
        Bir cümle yaz → Model sonucu göstersin.
        """
    )

    text_input = gr.Textbox(
        label="Cümle",
        placeholder="Bir cümle yazınız...",
        lines=4
    )

    analyze_button = gr.Button("Analiz Et")

    output = gr.Textbox(
        label="Duygu Sonucu",
        interactive=False
    )

    analyze_button.click(analyze, inputs=text_input, outputs=output)

demo.launch()