Spaces:
Sleeping
Sleeping
File size: 1,113 Bytes
db96f9a abaa2d8 ab55b01 db96f9a ab55b01 db96f9a ab55b01 db96f9a ab55b01 db96f9a ab55b01 33a9d12 db96f9a abaa2d8 db96f9a abaa2d8 ab55b01 | 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 | from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
import tensorflow as tf
import numpy as np
import gradio as gr
# Load tokenizer dan model
tokenizer = AutoTokenizer.from_pretrained("jeanetrixsiee/bert-finetuned-keras")
model = TFAutoModelForSequenceClassification.from_pretrained("jeanetrixsiee/bert-finetuned-keras")
# Label prediksi (urutan sesuai saat fine-tuning ya!)
labels = ['Negative', 'Neutral', 'Positive', 'Very Negative', 'Very Positive']
def predict_sentiment(text):
inputs = tokenizer(text, return_tensors="tf", truncation=True, padding=True, max_length=256)
logits = model(inputs)[0]
probs = tf.nn.softmax(logits, axis=1).numpy()[0]
pred_label = labels[np.argmax(probs)]
confidence = probs[np.argmax(probs)]
return f"{pred_label} (confidence: {confidence:.2f})"
demo = gr.Interface(
fn=predict_sentiment,
inputs=gr.Textbox(label="Enter a comment"),
outputs=gr.Textbox(label="Prediction"),
title="Sentiment Classifier",
description="Fine-tuned BERT using Hugging Face Transformers for sentiment analysis."
)
demo.launch()
|