Spaces:
Sleeping
Sleeping
File size: 1,539 Bytes
bd64784 44aa281 5eaa513 44aa281 3104665 988d809 44aa281 5eaa513 44aa281 f97685e 44aa281 bd64784 19185a1 adb3a4d 19185a1 5eaa513 44aa281 f97685e 44aa281 6c6b1d7 44aa281 5b878de 6c6b1d7 44aa281 bd64784 19185a1 44aa281 bd64784 2db743f 44aa281 f97685e 44aa281 5b878de 2db743f af111bc bd64784 | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 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()
|