uyuma commited on
Commit
f7f98b0
·
verified ·
1 Parent(s): be6ac44

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +26 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ MODEL_NAME = "kaixkhazaki/turkish-sentiment"
6
+ device = 0 if torch.cuda.is_available() else -1
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
10
+ sentiment = pipeline("text-classification", model=model, tokenizer=tokenizer, return_all_scores=True, device=device)
11
+
12
+ def analyze(text):
13
+ results = sentiment(text)[0]
14
+ results_sorted = sorted(results, key=lambda x: x["score"], reverse=True)
15
+ formatted = "\n".join([f"{r['label']}: {r['score']:.3f}" for r in results_sorted])
16
+ return formatted
17
+
18
+ demo = gr.Interface(
19
+ fn=analyze,
20
+ inputs=gr.Textbox(lines=3, placeholder="Bir metin yazın..."),
21
+ outputs=gr.Textbox(label="Duygu ve Skorlar"),
22
+ title="Türkçe Duygu Analizi (Skorlarla)",
23
+ description="Her etiket için olasılık skorlarını gösterir."
24
+ )
25
+
26
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers>=4.44.0
2
+ torch>=2.2.0
3
+ gradio>=4.44.0