chreed commited on
Commit
6c55a3c
โ€ข
1 Parent(s): 78f8896

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import gradio as gr
4
+
5
+ # ๋ชจ๋ธ๊ณผ ํ† ํฌ๋‚˜์ด์ € ๋กœ๋“œ
6
+ tokenizer = AutoTokenizer.from_pretrained("matthewburke/korean_sentiment")
7
+ model = AutoModelForSequenceClassification.from_pretrained("matthewburke/korean_sentiment")
8
+
9
+ # ์˜ˆ์ธก ํ•จ์ˆ˜ ์ •์˜
10
+ def predict_sentiment(text):
11
+ inputs = tokenizer(text, return_tensors="pt")
12
+ outputs = model(**inputs)
13
+ prediction = torch.argmax(outputs.logits, dim=-1)
14
+ labels = ["Negative", "Neutral", "Positive"]
15
+ return labels[prediction]
16
+
17
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
18
+ interface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text")
19
+ interface.launch()