Spaces:
Sleeping
Sleeping
| from transformers import pipeline | |
| import gradio as gr | |
| sentiment_model = pipeline( | |
| "sentiment-analysis", | |
| model="w11wo/indonesian-roberta-base-sentiment-classifier" | |
| ) | |
| ner_model = pipeline( | |
| "ner", | |
| model="cahya/bert-base-indonesian-NER", | |
| aggregation_strategy="simple" | |
| ) | |
| topic_model = pipeline( | |
| "text-classification", | |
| model="YagiASAFAS/indonesia-news-classification-bert" | |
| ) | |
| def analyze_text(text): | |
| if not text or not text.strip(): | |
| return {"error": "Teks kosong. Silakan masukkan kalimat Bahasa Indonesia."} | |
| sentiment = sentiment_model(text)[0] | |
| sentiment_result = { | |
| "label": sentiment["label"], | |
| "score": round(sentiment["score"], 4) | |
| } | |
| entities = ner_model(text) | |
| entity_result = [ | |
| {"entity": e["entity_group"], "word": e["word"], "score": round(e["score"], 4)} | |
| for e in entities | |
| ] | |
| topic = topic_model(text)[0] | |
| topic_result = { | |
| "label": topic["label"], | |
| "score": round(topic["score"], 4) | |
| } | |
| return { | |
| "sentiment": sentiment_result, | |
| "entities": entity_result, | |
| "topic": topic_result | |
| } | |
| demo = gr.Interface( | |
| fn=analyze_text, | |
| inputs=gr.Textbox(lines=3, placeholder="Masukkan kalimat Bahasa Indonesia..."), | |
| outputs=gr.JSON(label="Hasil Analisis"), | |
| title="Analisis Sentimen, Entitas, & Topik Bahasa Indonesia", | |
| description="Gunakan AI untuk analisis sentimen, pengenalan entitas, dan deteksi topik otomatis (multilingual)." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |