nhull commited on
Commit
c3367aa
·
verified ·
1 Parent(s): 457d325

Modify predictions output if all same

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -108,19 +108,21 @@ def analyze_sentiment_and_statistics(text):
108
 
109
  # Calculate statistics
110
  scores = list(results.values())
111
- if all(score == scores[0] for score in scores): # Check if all predictions are the same
 
 
 
 
 
 
112
  statistics = {
113
  "Message": "All models predict the same score.",
114
- "Average Score": f"{scores[0]:.2f}",
115
  }
116
  else:
117
- min_score_model = min(results, key=results.get)
118
- max_score_model = max(results, key=results.get)
119
- average_score = np.mean(scores)
120
-
121
  statistics = {
122
- "Lowest Score": f"{results[min_score_model]} (Model: {min_score_model})",
123
- "Highest Score": f"{results[max_score_model]} (Model: {max_score_model})",
124
  "Average Score": f"{average_score:.2f}",
125
  }
126
  return results, statistics
@@ -179,7 +181,7 @@ with gr.Blocks(css=".gradio-container { max-width: 900px; margin: auto; padding:
179
  # Button to analyze sentiment and show statistics
180
  def process_input_and_analyze(text_input):
181
  results, statistics = analyze_sentiment_and_statistics(text_input)
182
- if "Message" in statistics: # All models predicted the same score
183
  return (
184
  f"{results['DistilBERT']}",
185
  f"{results['Logistic Regression']}",
@@ -188,7 +190,7 @@ with gr.Blocks(css=".gradio-container { max-width: 900px; margin: auto; padding:
188
  f"{results['RoBERTa']}",
189
  f"Statistics:\n{statistics['Message']}\nAverage Score: {statistics['Average Score']}"
190
  )
191
- else: # Min and Max scores are present
192
  return (
193
  f"{results['DistilBERT']}",
194
  f"{results['Logistic Regression']}",
 
108
 
109
  # Calculate statistics
110
  scores = list(results.values())
111
+ min_score = min(scores)
112
+ max_score = max(scores)
113
+ min_score_models = [model for model, score in results.items() if score == min_score]
114
+ max_score_models = [model for model, score in results.items() if score == max_score]
115
+ average_score = np.mean(scores)
116
+
117
+ if all(score == scores[0] for score in scores):
118
  statistics = {
119
  "Message": "All models predict the same score.",
120
+ "Average Score": f"{average_score:.2f}",
121
  }
122
  else:
 
 
 
 
123
  statistics = {
124
+ "Lowest Score": f"{min_score} (Models: {', '.join(min_score_models)})",
125
+ "Highest Score": f"{max_score} (Models: {', '.join(max_score_models)})",
126
  "Average Score": f"{average_score:.2f}",
127
  }
128
  return results, statistics
 
181
  # Button to analyze sentiment and show statistics
182
  def process_input_and_analyze(text_input):
183
  results, statistics = analyze_sentiment_and_statistics(text_input)
184
+ if "Message" in statistics:
185
  return (
186
  f"{results['DistilBERT']}",
187
  f"{results['Logistic Regression']}",
 
190
  f"{results['RoBERTa']}",
191
  f"Statistics:\n{statistics['Message']}\nAverage Score: {statistics['Average Score']}"
192
  )
193
+ else:
194
  return (
195
  f"{results['DistilBERT']}",
196
  f"{results['Logistic Regression']}",