TuneMate / app.py
chreed's picture
Create app.py
6c55a3c verified
raw
history blame contribute delete
No virus
707 Bytes
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()