Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| model = pipeline("sentiment-analysis", model="kelompokjavonlp/sentiment_analysis") | |
| def predict_sentiment(text): | |
| if not text.strip(): | |
| return "Komentar kosong." | |
| result = model(text)[0] | |
| label = result['label'] | |
| score = result['score'] | |
| label_map = { | |
| "1 star": "Sangat Negatif π‘", | |
| "2 stars": "Negatif π ", | |
| "3 stars": "Netral π", | |
| "4 stars": "Positif π", | |
| "5 stars": "Sangat Positif π" | |
| } | |
| return f"Hasil: {label_map.get(label, label)}\nTingkat keyakinan: {score:.2f}" | |
| demo = gr.Interface( | |
| fn=predict_sentiment, | |
| inputs=gr.Textbox(lines=4, placeholder="Masukkan komentar YouTube..."), | |
| outputs="text", | |
| title="π¬ Analisis Sentimen Komentar YouTube", | |
| description="Masukkan komentar dan lihat hasil sentimennya." | |
| ) | |
| demo.launch() | |