Create app.py
Browse files
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()
|