Spaces:
Sleeping
Sleeping
File size: 981 Bytes
654b55a fc42c6d 654b55a fc42c6d 654b55a fc42c6d 654b55a fc42c6d 654b55a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
MODEL_ID = "JustParadis/indobert-sentiment-comment"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
model.eval()
LABELS = model.config.id2label # uses labels from training config
def predict(text):
inputs = tokenizer(
text,
return_tensors="pt",
truncation=True,
padding=True,
max_length=128
)
with torch.no_grad():
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=-1)[0]
return {
LABELS[i]: float(probs[i])
for i in range(len(probs))
}
gr.Interface(
fn=predict,
inputs=gr.Textbox(lines=4, placeholder="Masukkan komentar"),
outputs=gr.JSON(label="Prediction"),
title="IndoBERT Comment Sentiment",
description="2-label comment sentiment classification"
).launch() |