first one
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
sentiment_pipeline= pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
|
5 |
+
|
6 |
+
|
7 |
+
# texts = ["Hugging face? weired, but memorable.", "I am despirate"]
|
8 |
+
|
9 |
+
# results = sentiment_pipeline(texts)
|
10 |
+
|
11 |
+
# for text, results in zip(texts, results):
|
12 |
+
# print(f"Text: {text}")
|
13 |
+
# print(f"Sentiment: {result['label']}, Score: {result['score']:.4f}\n")
|
14 |
+
|
15 |
+
|
16 |
+
def predict_sentiment(text):
|
17 |
+
result = sentiment_pipeline(text)
|
18 |
+
return result[0]['label'], result[0]['score']
|
19 |
+
|
20 |
+
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs = ["label","number"])
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
iface.launch()
|
24 |
+
|