Spaces:
Runtime error
Runtime error
Commit
·
7f68476
1
Parent(s):
d961c51
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,28 +2,40 @@ from transformers import pipeline
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
"sentiment-analysis",
|
| 9 |
-
model=
|
| 10 |
-
tokenizer=
|
| 11 |
return_all_scores=True
|
| 12 |
)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
examples = [
|
| 15 |
"Masyarakat sangat kecewa dengan tragedi Kanjuruhan",
|
|
|
|
| 16 |
]
|
| 17 |
|
| 18 |
def sentiment_analysis(text):
|
| 19 |
-
output =
|
| 20 |
return {elm["label"]: elm["score"] for elm in output[0]}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
demo = gr.Interface(
|
| 23 |
-
fn=sentiment_analysis,
|
| 24 |
inputs=gr.Textbox(placeholder="Enter a sentence here..."),
|
| 25 |
-
outputs="label",
|
| 26 |
-
interpretation="default",
|
| 27 |
examples=[examples])
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
pretrained_sentiment = "w11wo/indonesian-roberta-base-sentiment-classifier"
|
| 6 |
+
pretrained_ner = "cahya/bert-base-indonesian-NER"
|
| 7 |
|
| 8 |
+
sentiment_pipeline = pipeline(
|
| 9 |
"sentiment-analysis",
|
| 10 |
+
model=pretrained_sentiment,
|
| 11 |
+
tokenizer=pretrained_sentiment,
|
| 12 |
return_all_scores=True
|
| 13 |
)
|
| 14 |
|
| 15 |
+
ner_pipeline = pipeline(
|
| 16 |
+
"ner",
|
| 17 |
+
model=pretrained_ner,
|
| 18 |
+
tokenizer=pretrained_ner
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
examples = [
|
| 22 |
"Masyarakat sangat kecewa dengan tragedi Kanjuruhan",
|
| 23 |
+
"Jokowi mengutuk kepolisian atas kerusuhan yang terjadi di Malang"
|
| 24 |
]
|
| 25 |
|
| 26 |
def sentiment_analysis(text):
|
| 27 |
+
output = sentiment_pipeline(text)
|
| 28 |
return {elm["label"]: elm["score"] for elm in output[0]}
|
| 29 |
+
|
| 30 |
+
def ner(text):
|
| 31 |
+
output = ner_pipeline(text)
|
| 32 |
+
return {"text": text, "entities": output}
|
| 33 |
|
| 34 |
demo = gr.Interface(
|
| 35 |
+
fn=[sentiment_analysis, ner],
|
| 36 |
inputs=gr.Textbox(placeholder="Enter a sentence here..."),
|
| 37 |
+
outputs=["label", gr.HighlightedText()],
|
| 38 |
+
interpretation=["default"],
|
| 39 |
examples=[examples])
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|