rpratap2102's picture
Update app.py
c89830e
raw
history blame
2.22 kB
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.', 'emoji': '😞'},
'Positive': {'text': 'This seems to be good news for the market.', 'emoji': 'πŸ˜ƒ'},
'Neutral': {'text': "This is normal in the market.", 'emoji': '😐'}
}
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, emoji, f"(Model Predicted it as {sentiment_label} with a confidence score of {confidence_score:.2f})"]
return f"{label_text} {emoji} (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.Text(label="Emoji"), 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()