rpratap2102 commited on
Commit
dfac358
·
1 Parent(s): d85b50f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import BertTokenizer, BertForSequenceClassification
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+
5
+ finbert = BertForSequenceClassification.from_pretrained('rpratap2102/The_Misfits', num_labels=3)
6
+ tokenizer = BertTokenizer.from_pretrained('rpratap2102/The_Misfits')
7
+
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
+ return c_labels[sentiment_label]
20
+
21
+
22
+
23
+ iface = gr.Interface(
24
+ fn=predict_sentiment,
25
+ inputs="text",
26
+ outputs="text",
27
+ live=True,
28
+ capture_session=True
29
+ )
30
+
31
+ iface.launch()