Spaces:
Sleeping
Sleeping
Download app.py from galennolan/indoemotion: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/galennolan/indoemotion/resolve/main/app.py
- Command line
-
hf download hf://spaces/galennolan/indoemotion/app.py
-
curl -L -o app.py https://huggingface.co/spaces/galennolan/indoemotion/resolve/main/app.py
1.09 kB
| 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() | |