Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline | |
| # Load model & tokenizer dari Hugging Face Hub | |
| model = AutoModelForSequenceClassification.from_pretrained("galennolan/indobert-b-p1-indoemotion-5class") | |
| tokenizer = AutoTokenizer.from_pretrained("galennolan/indobert-b-p1-indoemotion-5class") | |
| # Inisialisasi pipeline | |
| emotion_classifier = pipeline("text-classification", model=model, tokenizer=tokenizer) | |
| # Fungsi prediksi | |
| def predict_emotion(text): | |
| result = emotion_classifier(text)[0] | |
| label = result['label'] | |
| score = round(result['score'], 4) | |
| return f"{label} ({score})" | |
| # Gradio Interface | |
| demo = gr.Interface(fn=predict_emotion, | |
| inputs=gr.Textbox(lines=3, placeholder="Masukkan teks..."), | |
| outputs="text", | |
| title="Klasifikasi Emosi Bahasa Indonesia", | |
| description="Model IndoBERT untuk mendeteksi 5 emosi dari teks Bahasa Indonesia.") | |
| # Jalankan saat local testing | |
| if __name__ == "__main__": | |
| demo.launch() | |