jarif commited on
Commit
2f9404f
1 Parent(s): 833148b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -8
app.py CHANGED
@@ -22,7 +22,7 @@ def predict_sentiment(custom_data):
22
  st.error(f"Model file not found: {model_path}")
23
  return None
24
  model = load_model(model_path)
25
-
26
  # Load the one-hot encoding information
27
  one_hot_info_path = 'one_hot_info_1.pkl'
28
  if not os.path.exists(one_hot_info_path):
@@ -50,17 +50,13 @@ def predict_sentiment(custom_data):
50
  # Predict the sentiments for all tweets
51
  predictions = model.predict(np.array(padded_texts))
52
 
53
- # Debug: Print predictions
54
- st.write("Debug: Predictions")
55
- st.write(predictions)
56
-
57
  # Convert predictions to class labels and probabilities
58
  predicted_sentiments = []
59
  for prediction in predictions:
60
- sentiment_probabilities = {label: round(prob, 4) for label, prob in zip(labels_with_emojis.keys(), prediction)}
61
  sentiment = np.argmax(prediction)
62
  sentiment_label = list(labels_with_emojis.keys())[sentiment]
63
  sentiment_emoji = labels_with_emojis[sentiment_label]
 
64
  predicted_sentiments.append((sentiment_label, sentiment_emoji, sentiment_probabilities))
65
 
66
  return predicted_sentiments
@@ -76,10 +72,10 @@ if st.button('Analyze'):
76
  if user_input.strip(): # Check if input is not empty
77
  # Remove emojis and replace with their description
78
  user_input = emoji.demojize(user_input)
79
-
80
  # Split input by newlines to handle multiple tweets
81
  tweets = user_input.split('\n')
82
-
83
  # Predict sentiment for custom data
84
  predicted_sentiments = predict_sentiment(tweets)
85
 
 
22
  st.error(f"Model file not found: {model_path}")
23
  return None
24
  model = load_model(model_path)
25
+
26
  # Load the one-hot encoding information
27
  one_hot_info_path = 'one_hot_info_1.pkl'
28
  if not os.path.exists(one_hot_info_path):
 
50
  # Predict the sentiments for all tweets
51
  predictions = model.predict(np.array(padded_texts))
52
 
 
 
 
 
53
  # Convert predictions to class labels and probabilities
54
  predicted_sentiments = []
55
  for prediction in predictions:
 
56
  sentiment = np.argmax(prediction)
57
  sentiment_label = list(labels_with_emojis.keys())[sentiment]
58
  sentiment_emoji = labels_with_emojis[sentiment_label]
59
+ sentiment_probabilities = {label: round(prob, 4) for label, prob in zip(labels_with_emojis.keys(), prediction)}
60
  predicted_sentiments.append((sentiment_label, sentiment_emoji, sentiment_probabilities))
61
 
62
  return predicted_sentiments
 
72
  if user_input.strip(): # Check if input is not empty
73
  # Remove emojis and replace with their description
74
  user_input = emoji.demojize(user_input)
75
+
76
  # Split input by newlines to handle multiple tweets
77
  tweets = user_input.split('\n')
78
+
79
  # Predict sentiment for custom data
80
  predicted_sentiments = predict_sentiment(tweets)
81