|
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] |
|
|
|
|
|
interface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text") |
|
interface.launch() |
|
|