Spaces:
Runtime error
Runtime error
File size: 1,385 Bytes
2168cf5 6ce2f8e 2168cf5 7f68476 2168cf5 7f68476 ef26fd6 7f68476 a60235f 2168cf5 7f68476 2168cf5 42535f1 2168cf5 ef26fd6 7f68476 d961c51 7f68476 2168cf5 c0d80b6 53c2635 92bbd4b 8289c6f 2168cf5 0fc2865 92bbd4b 0fc2865 8289c6f c0d80b6 2168cf5 6ce2f8e 8289c6f 92bbd4b dc02166 |
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 |
from transformers import pipeline
import gradio as gr
from gradio.mix import Parallel
pretrained_sentiment = "w11wo/indonesian-roberta-base-sentiment-classifier"
pretrained_ner = "cahya/bert-base-indonesian-NER"
sentiment_pipeline = pipeline(
"sentiment-analysis",
model=pretrained_sentiment,
tokenizer=pretrained_sentiment,
return_all_scores=True
)
ner_pipeline = pipeline(
"ner",
model=pretrained_ner,
tokenizer=pretrained_ner
)
examples = [
"Jokowi sangat kecewa dengan POLRI atas kerusuhan yang terjadi di Malang",
"Lesti marah terhadap perlakuan KDRT yang dilakukan oleh Bilar",
"Ungkapan rasa bahagia diutarakan oleh Coki Pardede karena kebabasannya dari penjara"
]
def sentiment_analysis(text):
output = sentiment_pipeline(text)
return {elm["label"]: elm["score"] for elm in output[0]}
def ner(text):
output = ner_pipeline(text)
return {"text": text, "entities": output}
sentiment_demo = gr.Interface(
fn=sentiment_analysis,
inputs="text",
outputs="label")
ner_demo = gr.Interface(
ner,
"text",
gr.HighlightedText(),
examples=examples)
if __name__ == "__main__":
Parallel(sentiment_demo, ner_demo,
inputs=gr.Textbox(lines=10, label="Input Text", placeholder="Enter sentences here..."),
title="Entity Based Sentiment Analysis Indonesia",
examples=examples).launch() |