Spaces:
Sleeping
Sleeping
File size: 2,215 Bytes
dfac358 e88230c dfac358 e88230c dfac358 10ceb34 c89830e e88230c dfac358 c89830e 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 |
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()
|