rpratap2102 commited on
Commit
8200983
β€’
1 Parent(s): c89830e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -17,11 +17,15 @@ tokenizer = BertTokenizer.from_pretrained('rpratap2102/The_Misfits')
17
  nlp = pipeline("sentiment-analysis", model=finbert, tokenizer=tokenizer)
18
 
19
  c_labels = {
20
- 'Negative': {'text': 'This does not look good for the Market.', 'emoji': '😞'},
21
- 'Positive': {'text': 'This seems to be good news for the market.', 'emoji': 'πŸ˜ƒ'},
22
- 'Neutral': {'text': "This is normal in the market.", 'emoji': '😐'}
23
  }
24
 
 
 
 
 
25
  def predict_sentiment(text):
26
  result = nlp([text])[0]
27
  sentiment_label = result['label']
@@ -30,13 +34,13 @@ def predict_sentiment(text):
30
  label_text = c_labels[sentiment_label]['text']
31
  emoji = c_labels[sentiment_label]['emoji']
32
 
33
- return [label_text, emoji, f"(Model Predicted it as {sentiment_label} with a confidence score of {confidence_score:.2f})"]
34
- return f"{label_text} {emoji} (Model Predicted it as {sentiment_label} with a confidence score of {confidence_score:.2f})"
35
 
36
  iface = gr.Interface(
37
  fn=predict_sentiment,
38
  inputs=gr.Text(label="Enter statement to analyze:", placeholder="Type here..."),
39
- outputs=[gr.Text(label="Sentiment Analysis"), gr.Text(label="Emoji"), gr.Text(label="Model Prediction Info")],
40
  title="The Misfits Financial Sentimanet Analysis App",
41
  description="Financial Sentiment Analysis is a process of using natural language processing (NLP) and machine learning techniques to analyze and determine the sentiment expressed in financial news, social media, and other textual data related to financial markets. The goal is to understand the emotions and opinions of market participants towards specific financial instruments, companies, or the overall market."
42
  )
 
17
  nlp = pipeline("sentiment-analysis", model=finbert, tokenizer=tokenizer)
18
 
19
  c_labels = {
20
+ 'Negative': {'text': 'This does not look good for the Market.', 'image': 'negative.png'},
21
+ 'Positive': {'text': 'This seems to be good news for the market.', 'image': 'positive.png'},
22
+ 'Neutral': {'text': "This is normal in the market.", 'image': 'neutral.png'}
23
  }
24
 
25
+ def load_image(file_name):
26
+ with open(file_name, "rb") as f:
27
+ return f.read()
28
+
29
  def predict_sentiment(text):
30
  result = nlp([text])[0]
31
  sentiment_label = result['label']
 
34
  label_text = c_labels[sentiment_label]['text']
35
  emoji = c_labels[sentiment_label]['emoji']
36
 
37
+ return [label_text, gr.Image(image_data), f"(Model Predicted it as {sentiment_label} with a confidence score of {confidence_score:.2f})"]
38
+
39
 
40
  iface = gr.Interface(
41
  fn=predict_sentiment,
42
  inputs=gr.Text(label="Enter statement to analyze:", placeholder="Type here..."),
43
+ outputs=[gr.Text(label="Sentiment Analysis"), gr.Image(label="", type="file"), gr.Text(label="Model Prediction Info")],
44
  title="The Misfits Financial Sentimanet Analysis App",
45
  description="Financial Sentiment Analysis is a process of using natural language processing (NLP) and machine learning techniques to analyze and determine the sentiment expressed in financial news, social media, and other textual data related to financial markets. The goal is to understand the emotions and opinions of market participants towards specific financial instruments, companies, or the overall market."
46
  )