Spaces:
Runtime error
Runtime error
File size: 1,241 Bytes
2168cf5 53c2635 2168cf5 7f68476 2168cf5 7f68476 ef26fd6 7f68476 a60235f 2168cf5 7f68476 2168cf5 d961c51 7f68476 2168cf5 ef26fd6 7f68476 d961c51 7f68476 2168cf5 c0d80b6 53c2635 0fc2865 c0d80b6 0fc2865 2168cf5 0fc2865 c0d80b6 2168cf5 0fc2865 |
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 |
from transformers import pipeline
import gradio as gr
from gradio.mix import Series
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 = [
"Masyarakat sangat kecewa dengan tragedi Kanjuruhan",
"Jokowi mengutuk kepolisian atas kerusuhan yang terjadi di Malang"
]
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=gr.Textbox(placeholder="Enter sentence here...")
outputs="label",
interpretation="default",
examples=[examples])
ner_demo = gr.Interface(
ner,
gr.Textbox(placeholder="Enter sentence here...")
gr.HighlightedText(),
examples=[examples])
if __name__ == "__main__":
Series(sentiment_demo, ner_demo).launch() |