samet214 commited on
Commit
e5e4ddf
·
verified ·
1 Parent(s): 620dfad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Duygu analizi modelini yükle
5
+ model_name = "savasy/bert-base-turkish-sentiment-cased"
6
+ sentiment_pipeline = pipeline("sentiment-analysis", model=model_name)
7
+
8
+ def analyze_sentiment(text):
9
+ # Modelden tahmini al
10
+ result = sentiment_pipeline(text)[0]
11
+ # Modelin çıktısını projenin istediği formata (pozitif/nötr/negatif) dönüştür
12
+ label = result['label']
13
+ if label == "positive":
14
+ return "pozitif"
15
+ elif label == "negative":
16
+ return "negatif"
17
+ else:
18
+ return "nötr"
19
+
20
+ # Gradio arayüzünü ve API'yi oluştur
21
+ iface = gr.Interface(
22
+ fn=analyze_sentiment,
23
+ inputs=gr.Textbox(lines=2, placeholder="Analiz edilecek metni buraya girin..."),
24
+ outputs="text",
25
+ title="Türkçe Duygu Analizi API",
26
+ description="Girilen cümlenin duygu durumunu (pozitif, nötr, negatif) analiz eder."
27
+ )
28
+
29
+ # Arayüzü başlat
30
+ iface.launch()