Spaces:
Sleeping
Sleeping
Commit
Β·
10ceb34
1
Parent(s):
885a6d8
Update app.py
Browse files
app.py
CHANGED
@@ -8,22 +8,29 @@ tokenizer = BertTokenizer.from_pretrained('rpratap2102/The_Misfits')
|
|
8 |
nlp = pipeline("sentiment-analysis", model=finbert, tokenizer=tokenizer)
|
9 |
|
10 |
c_labels = {
|
11 |
-
'Negative': 'This does not look good for the Market',
|
12 |
-
'Positive': 'This seems to be good news for the market',
|
13 |
-
'Neutral': "This is normal in the market"
|
14 |
}
|
15 |
|
16 |
def predict_sentiment(text):
|
17 |
result = nlp([text])[0]
|
18 |
sentiment_label = result['label']
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
fn=predict_sentiment,
|
25 |
inputs="text",
|
26 |
outputs="text",
|
|
|
|
|
27 |
)
|
28 |
|
29 |
-
iface.launch()
|
|
|
8 |
nlp = pipeline("sentiment-analysis", model=finbert, tokenizer=tokenizer)
|
9 |
|
10 |
c_labels = {
|
11 |
+
'Negative': {'text': 'This does not look good for the Market', 'emoji': 'π'},
|
12 |
+
'Positive': {'text': 'This seems to be good news for the market', 'emoji': 'π'},
|
13 |
+
'Neutral': {'text': "This is normal in the market", 'emoji': 'π'}
|
14 |
}
|
15 |
|
16 |
def predict_sentiment(text):
|
17 |
result = nlp([text])[0]
|
18 |
sentiment_label = result['label']
|
19 |
+
confidence_score = result['score']
|
20 |
+
|
21 |
+
label_text = c_labels[sentiment_label]['text']
|
22 |
+
emoji = c_labels[sentiment_label]['emoji']
|
23 |
+
|
24 |
+
output_text = f"{label_text} ({sentiment_label}) with a confidence score of {confidence_score:.2f}"
|
25 |
+
|
26 |
+
return f"{emoji} {output_text}"
|
27 |
|
28 |
iface = gr.Interface(
|
29 |
fn=predict_sentiment,
|
30 |
inputs="text",
|
31 |
outputs="text",
|
32 |
+
live=True,
|
33 |
+
capture_session=True
|
34 |
)
|
35 |
|
36 |
+
iface.launch()
|