File size: 707 Bytes
6c55a3c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import gradio as gr
# ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ก๋
tokenizer = AutoTokenizer.from_pretrained("matthewburke/korean_sentiment")
model = AutoModelForSequenceClassification.from_pretrained("matthewburke/korean_sentiment")
# ์์ธก ํจ์ ์ ์
def predict_sentiment(text):
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
prediction = torch.argmax(outputs.logits, dim=-1)
labels = ["Negative", "Neutral", "Positive"]
return labels[prediction]
# Gradio ์ธํฐํ์ด์ค ์ ์
interface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text")
interface.launch()
|