khandelwalkishna15 commited on
Commit
f5c9839
1 Parent(s): 6d2354e

new look change

Browse files
Files changed (1) hide show
  1. app.py +33 -14
app.py CHANGED
@@ -1,11 +1,17 @@
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
 
4
- # Load pre-trained model and tokenizer
5
- model_name = "mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis" # Replace with your chosen model
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
 
 
 
 
 
 
 
 
9
  def predict_sentiment(text):
10
  inputs = tokenizer(text, return_tensors="pt")
11
  outputs = model(**inputs)
@@ -14,18 +20,31 @@ def predict_sentiment(text):
14
  predicted_sentiment = sentiment_mapping.get(sentiment_class, 'Unknown')
15
  return predicted_sentiment
16
 
17
- def main():
18
- st.title("Financial Sentiment Analysis")
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- # Get user input
21
- text = st.text_area("Enter financial content:")
 
 
 
 
 
22
 
23
- if st.button("Classify Sentiment"):
24
- if text:
25
- predicted_sentiment = predict_sentiment(text)
26
- st.success(f"Predicted sentiment: {predicted_sentiment}")
27
- else:
28
- st.warning("Please enter some text.")
29
 
30
- if __name__ == "__main__":
31
- main()
 
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
 
4
+ model_name = "mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis"
 
5
  tokenizer = AutoTokenizer.from_pretrained(model_name)
6
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
 
8
+ # Set the page title
9
+ st.title("Financial Sentiment Analysis App")
10
+
11
+ # Add a text input for the user to input financial news
12
+ text_input = st.text_area("Enter Financial News:", "Tesla stock is soaring after record-breaking earnings.")
13
+
14
+ # Function to perform sentiment analysis
15
  def predict_sentiment(text):
16
  inputs = tokenizer(text, return_tensors="pt")
17
  outputs = model(**inputs)
 
20
  predicted_sentiment = sentiment_mapping.get(sentiment_class, 'Unknown')
21
  return predicted_sentiment
22
 
23
+ # Button to trigger sentiment analysis
24
+ if st.button("Analyze Sentiment"):
25
+ # Check if the input text is not empty
26
+ if text_input:
27
+ # Show loading spinner while processing
28
+ with st.spinner("Analyzing sentiment..."):
29
+ sentiment = predict_sentiment(text_input)
30
+ # Change the view based on the predicted sentiment
31
+ st.success(f"Sentiment: {sentiment}")
32
+ if sentiment == 'Positive':
33
+ st.balloons() # Celebratory animation for positive sentiment
34
+ # Add additional views for other sentiments as needed
35
+ else:
36
+ st.warning("Please enter some text for sentiment analysis.")
37
 
38
+ # Optional: Display the raw sentiment scores
39
+ if st.checkbox("Show Raw Sentiment Scores"):
40
+ if text_input:
41
+ inputs = tokenizer(text_input, return_tensors="pt")
42
+ outputs = model(**inputs)
43
+ raw_scores = outputs.logits[0].tolist()
44
+ st.info(f"Raw Sentiment Scores: {raw_scores}")
45
 
46
+ # Optional: Display additional information or analysis
47
+ # Add more components as needed for your specific use case
 
 
 
 
48
 
49
+ # Add a footer
50
+ st.text("Built with Streamlit and Transformers")