Update app.py
Browse files
app.py
CHANGED
|
@@ -3,31 +3,20 @@ from transformers import pipeline
|
|
| 3 |
|
| 4 |
MODEL = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
classifier = pipeline(
|
| 8 |
-
"sentiment-analysis",
|
| 9 |
-
model=MODEL
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
label_map = {
|
| 13 |
-
"LABEL_0": "Negative",
|
| 14 |
-
"LABEL_1": "Neutral",
|
| 15 |
-
"LABEL_2": "Positive"
|
| 16 |
-
}
|
| 17 |
|
| 18 |
def analyze(text):
|
| 19 |
result = classifier(text)[0]
|
| 20 |
return {
|
| 21 |
-
"Sentiment":
|
| 22 |
"Confidence": f"{result['score']:.2%}"
|
| 23 |
}
|
| 24 |
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=analyze,
|
| 27 |
-
inputs=gr.Textbox(lines=4
|
| 28 |
outputs="json",
|
| 29 |
-
title="
|
| 30 |
-
description="Runs locally using Transformers inside HF Spaces"
|
| 31 |
)
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
|
|
|
| 3 |
|
| 4 |
MODEL = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
| 5 |
|
| 6 |
+
classifier = pipeline("sentiment-analysis", model=MODEL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def analyze(text):
|
| 9 |
result = classifier(text)[0]
|
| 10 |
return {
|
| 11 |
+
"Sentiment": result["label"].capitalize(),
|
| 12 |
"Confidence": f"{result['score']:.2%}"
|
| 13 |
}
|
| 14 |
|
| 15 |
demo = gr.Interface(
|
| 16 |
fn=analyze,
|
| 17 |
+
inputs=gr.Textbox(lines=4),
|
| 18 |
outputs="json",
|
| 19 |
+
title="Sentiment Analyzer"
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
if __name__ == "__main__":
|