Katake commited on
Commit
c147591
·
verified ·
1 Parent(s): ef03384

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -13
app.py CHANGED
@@ -1,20 +1,53 @@
1
  import gradio as gr
2
  from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
3
 
4
- # Model ve tokenizer bir kere yükleniyor (performans için önemli)
5
- model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
6
- tokenizer = AutoTokenizer.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
 
 
 
 
 
 
 
 
 
 
7
 
8
- sentiment_pipe = pipeline("sentiment-analysis", tokenizer=tokenizer, model=model)
 
 
 
 
 
 
 
9
 
10
- def greet(text):
11
- result = sentiment_pipe(text)[0]['label']
12
- return result
 
 
 
 
 
 
13
 
14
- iface = gr.Interface(
15
- fn=greet,
16
- inputs=gr.Textbox(placeholder="Lütfen Cümle Giriniz...", lines=5),
17
- outputs=gr.Textbox(label="Duygu Analizi Sonucu")
18
- )
 
 
 
 
 
 
 
 
 
 
19
 
20
- iface.launch()
 
1
  import gradio as gr
2
  from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
3
 
4
+ # Modeli 1 kez yükle (hız için)
5
+ model = AutoModelForSequenceClassification.from_pretrained(
6
+ "savasy/bert-base-turkish-sentiment-cased"
7
+ )
8
+ tokenizer = AutoTokenizer.from_pretrained(
9
+ "savasy/bert-base-turkish-sentiment-cased"
10
+ )
11
+
12
+ sentiment_pipe = pipeline(
13
+ "sentiment-analysis",
14
+ tokenizer=tokenizer,
15
+ model=model
16
+ )
17
 
18
+ def analyze(text):
19
+ result = sentiment_pipe(text)[0]["label"]
20
+ if result == "positive":
21
+ return "🔵 POZİTİF"
22
+ elif result == "negative":
23
+ return "🔴 NEGATİF"
24
+ else:
25
+ return "🟡 NÖTR"
26
 
27
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
28
+ gr.Markdown(
29
+ """
30
+ # 🇹🇷 Türkçe Duygu Analizi
31
+ BERT tabanlı Türkçe cümle analiz modeli
32
+
33
+ Bir cümle yaz → Model sana **POZİTİF / NEGATİF / NÖTR** sonucunu söylesin.
34
+ """
35
+ )
36
 
37
+ with gr.Row():
38
+ text_input = gr.Textbox(
39
+ label="Cümle",
40
+ placeholder="Bir cümle yazınız...",
41
+ lines=4
42
+ )
43
+
44
+ analyze_button = gr.Button("Analiz Et")
45
+
46
+ output = gr.Textbox(
47
+ label="Duygu Sonucu",
48
+ interactive=False
49
+ )
50
+
51
+ analyze_button.click(analyze, inputs=text_input, outputs=output)
52
 
53
+ demo.launch()