File size: 2,212 Bytes
dfac358
 
 
 
e88230c
 
 
 
 
 
 
 
 
dfac358
 
 
 
 
 
088d37e
 
 
dfac358
 
8200983
 
 
 
dfac358
 
 
10ceb34
 
 
 
c89830e
8200983
 
dfac358
 
 
c89830e
70525b1
65021a6
 
dfac358
 
10ceb34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from transformers import BertTokenizer, BertForSequenceClassification
from transformers import pipeline
import gradio as gr

finbert = BertForSequenceClassification.from_pretrained('rpratap2102/The_Misfits', num_labels=3)
tokenizer = BertTokenizer.from_pretrained('rpratap2102/The_Misfits')

nlp = pipeline("sentiment-analysis", model=finbert, tokenizer=tokenizer)

from transformers import BertTokenizer, BertForSequenceClassification
from transformers import pipeline


finbert = BertForSequenceClassification.from_pretrained('rpratap2102/The_Misfits', num_labels=3)
tokenizer = BertTokenizer.from_pretrained('rpratap2102/The_Misfits')

nlp = pipeline("sentiment-analysis", model=finbert, tokenizer=tokenizer)

c_labels = {
    'Negative': {'text': 'This does not look good for the Market.', 'image': 'negative.gif'},
    'Positive': {'text': 'This seems to be good news for the market.', 'image': 'positive.gif'},
    'Neutral': {'text': "This is normal in the market.", 'image': 'neutral.gif'}
}

def load_image(file_name):
    with open(file_name, "rb") as f:
        return f.read()

def predict_sentiment(text):
    result = nlp([text])[0]
    sentiment_label = result['label']
    confidence_score = result['score']
    
    label_text = c_labels[sentiment_label]['text']
    emoji = c_labels[sentiment_label]['emoji']

    return [label_text, gr.Image(image_data), f"(Model Predicted it as {sentiment_label} with a confidence score of {confidence_score:.2f})"]


iface = gr.Interface(
    fn=predict_sentiment,
    inputs=gr.Text(label="Enter statement to analyze:", placeholder="Type here..."),
    outputs=[gr.Text(label="Sentiment Analysis"), gr.Image(label=""), gr.Text(label="Model Prediction Info")],
    title="The Misfits Financial Sentimanet Analysis App",
    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."
)

iface.launch()