|
|
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline |
|
from transformers_interpret import SequenceClassificationExplainer |
|
model = AutoModelForSequenceClassification.from_pretrained("indobertweet-fine-tuned") |
|
tokenizer = AutoTokenizer.from_pretrained("indolem/indobertweet-base-uncased") |
|
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer) |
|
|
|
def classify(text): |
|
text = text.strip().lower() |
|
result = classifier(text) |
|
yhat = result[0]['label'] |
|
return result |
|
|
|
|
|
|
|
import gradio as gr |
|
|
|
iface = gr.Interface( |
|
fn=classify, |
|
inputs=[ |
|
gr.Textbox(placeholder="Lewandowski bermain buruk sekali, Xavi benar-benar marah kepadanya", label="Enter text to classify emotions", lines=5) |
|
], |
|
outputs=gr.Textbox(label="Classification Result"), |
|
title="🔮 Emotion Classification", |
|
description="Enter a text and classify its emotions." |
|
) |
|
iface.launch() |