abullard1 commited on
Commit
24bce51
โ€ข
1 Parent(s): 04ff325

Fix Classifier Score to Label Mappings in Gradio Interface

Browse files
Files changed (1) hide show
  1. app.py +19 -24
app.py CHANGED
@@ -47,20 +47,11 @@ def classify_steam_review(input_text):
47
 
48
 
49
  # Provides a textual representation of the classification result
50
- def get_steam_review_classification_result_text(label_1, score_1, label_2, score_2):
51
- # Maps label values to constructiveness
52
- def label_to_constructiveness(label):
53
- return "Constructive" if label == "LABEL_1" else "Not Constructive"
54
-
55
- # Formats the output in a readable format
56
- def format_output(label, score, emoji):
57
- return f'{label_to_constructiveness(label)} with a score of {score}. {emoji}'
58
-
59
- # Determines the label and score with the highest score
60
- if score_1 >= score_2:
61
- return format_output(label_1, score_1, "๐Ÿ‘๐Ÿป")
62
  else:
63
- return format_output(label_2, score_2, "๐Ÿ‘Ž๐Ÿป")
64
 
65
 
66
  # Examples Steam Reviews to display in the Gradio Interface using the "examples" parameter
@@ -74,7 +65,7 @@ examples = [
74
  # HTML article to display in the Gradio Interface using the "article" parameter
75
  article = (
76
  """
77
- *Format your input as follows for the best results: **Review**: {review_text}, **Playtime**: {author_playtime_at_review}, **Voted Up**: {voted_up}, **Upvotes**: {upvotes}, **Votes Funny**: {votes_funny}.*
78
  """
79
  )
80
 
@@ -124,14 +115,18 @@ with gr.Blocks() as steam_reviews_classifier_block:
124
  # Function to run when the Submit Button is clicked (Passes the input text to the classifier and displays the output text)
125
  def on_submit_click(input_text):
126
  classification_result = classify_steam_review(input_text)
127
- classification_result_text = get_steam_review_classification_result_text(
128
- label_1=classification_result["label_1"],
129
- score_1=classification_result["score_1"],
130
- label_2=classification_result["label_2"],
131
- score_2=classification_result["score_2"]
132
- )
133
- output_text = classification_result_text
134
- constructive, not_constructive = str(classification_result["score_1"]), str(classification_result["score_2"])
 
 
 
 
135
  return output_text, constructive, not_constructive
136
 
137
 
@@ -139,8 +134,8 @@ with gr.Blocks() as steam_reviews_classifier_block:
139
  submit_button.click(
140
  fn=on_submit_click,
141
  inputs=input_textbox,
142
- outputs=[output_textbox, not_constructive_label, constructive_label]
143
  )
144
 
145
  # Launches the Gradio Blocks Interface
146
- steam_reviews_classifier_block.launch()
 
47
 
48
 
49
  # Provides a textual representation of the classification result
50
+ def get_steam_review_classification_result_text(label_1, score_1):
51
+ if label_1 == "LABEL_1":
52
+ return f"Constructive with a score of {score_1}. ๐Ÿ‘๐Ÿป"
 
 
 
 
 
 
 
 
 
53
  else:
54
+ return f"Not Constructive with a score of {score_1}. ๐Ÿ‘Ž๐Ÿป"
55
 
56
 
57
  # Examples Steam Reviews to display in the Gradio Interface using the "examples" parameter
 
65
  # HTML article to display in the Gradio Interface using the "article" parameter
66
  article = (
67
  """
68
+ Format your input as follows for the best results: ***Review**: {review_text}, **Playtime**: {author_playtime_at_review}, **Voted Up**: {voted_up}, **Upvotes**: {upvotes}, **Votes Funny**: {votes_funny}.*
69
  """
70
  )
71
 
 
115
  # Function to run when the Submit Button is clicked (Passes the input text to the classifier and displays the output text)
116
  def on_submit_click(input_text):
117
  classification_result = classify_steam_review(input_text)
118
+ label_1 = classification_result["label_1"]
119
+ score_1 = classification_result["score_1"]
120
+ score_2 = classification_result["score_2"]
121
+
122
+ output_text = get_steam_review_classification_result_text(label_1, score_1)
123
+
124
+ # Maps the scores to the constructive and not constructive labels in the Gradio Interface
125
+ if label_1 == "LABEL_1":
126
+ constructive, not_constructive = score_1, score_2
127
+ else:
128
+ constructive, not_constructive = score_2, score_1
129
+
130
  return output_text, constructive, not_constructive
131
 
132
 
 
134
  submit_button.click(
135
  fn=on_submit_click,
136
  inputs=input_textbox,
137
+ outputs=[output_textbox, constructive_label, not_constructive_label]
138
  )
139
 
140
  # Launches the Gradio Blocks Interface
141
+ steam_reviews_classifier_block.launch()