Ahmad-Moiz commited on
Commit
c910b2f
1 Parent(s): 8ffecbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -6
app.py CHANGED
@@ -2,15 +2,12 @@ import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
 
5
- # Load the tokenizer and model
6
  tokenizer = AutoTokenizer.from_pretrained("mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
7
  model = AutoModelForSequenceClassification.from_pretrained("mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
8
 
9
- # Set the model to evaluation mode
10
  model.eval()
11
 
12
  def predict_sentiment(text):
13
- # Tokenize the input text and prepare it to be used as model input
14
  inputs = tokenizer.encode_plus(
15
  text,
16
  add_special_tokens=True,
@@ -19,12 +16,10 @@ def predict_sentiment(text):
19
  truncation=True
20
  )
21
 
22
- # Perform the prediction
23
  with torch.no_grad():
24
  outputs = model(**inputs)
25
  predicted_class = torch.argmax(outputs.logits, dim=1).item()
26
 
27
- # Determine the sentiment based on the predicted class
28
  if predicted_class == 0:
29
  return "Negative sentiment"
30
  elif predicted_class == 1:
@@ -35,7 +30,7 @@ def predict_sentiment(text):
35
  # Streamlit interface
36
  st.title("Financial News Sentiment Analysis")
37
 
38
- user_input = st.text_area("Enter the financial news text:")
39
  if st.button("Analyze"):
40
  if user_input:
41
  # Get the sentiment prediction
 
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
 
 
5
  tokenizer = AutoTokenizer.from_pretrained("mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
6
  model = AutoModelForSequenceClassification.from_pretrained("mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
7
 
 
8
  model.eval()
9
 
10
  def predict_sentiment(text):
 
11
  inputs = tokenizer.encode_plus(
12
  text,
13
  add_special_tokens=True,
 
16
  truncation=True
17
  )
18
 
 
19
  with torch.no_grad():
20
  outputs = model(**inputs)
21
  predicted_class = torch.argmax(outputs.logits, dim=1).item()
22
 
 
23
  if predicted_class == 0:
24
  return "Negative sentiment"
25
  elif predicted_class == 1:
 
30
  # Streamlit interface
31
  st.title("Financial News Sentiment Analysis")
32
 
33
+ user_input = st.text_area("Made by Ahmad Moiz with Love","Enter the financial news text:")
34
  if st.button("Analyze"):
35
  if user_input:
36
  # Get the sentiment prediction