JRQi commited on
Commit
6040d3c
β€’
1 Parent(s): 7a4787f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -70
app.py CHANGED
@@ -71,28 +71,6 @@ Choose one of the three tasks below ... and start to play!
71
 
72
  )
73
  with gr.Column():
74
- # data = pd.DataFrame(
75
- # {
76
- # "Role": ["AI πŸ€–", "HUMAN πŸ‘¨πŸ‘©"],
77
- # "Scores": [0, 0],
78
- # }
79
- # )
80
- # plot = gr.BarPlot(
81
- # data,
82
- # x="Role",
83
- # y="Scores",
84
- # color="Role",
85
- # vertical=False,
86
- # y_lim=[0,10],
87
- # color_legend_position='none',
88
- # height=250,
89
- # width=500,
90
- # show_label=False,
91
- # container=False,
92
- # )
93
- # tooltip=["Role", "Scores"],
94
-
95
- # button_reset = gr.Button("Reset Scores")
96
  logo = gr.Image('logo.png', height=230, width=640, min_width=80, show_label=False, show_share_button=False, interactive=False, container=False)
97
 
98
  gr.Markdown(
@@ -103,40 +81,25 @@ Choose one of the three tasks below ... and start to play!
103
  ''' ### <p style="text-align: center;"> Machine &ensp; ''' + str(int(0)) + ''' &ensp; VS &ensp; ''' + str(int(0)) + ''' &ensp; Human </p>'''
104
  )
105
 
106
- # score_robot = gr.Markdown(
107
- # ''' ## Robot: ''' + str(int(num2.value))
108
- # )
109
-
110
- # score_human = gr.Markdown(
111
- # ''' ## Human: ''' + str(int(num1.value))
112
- # )
113
-
114
- # button_reset.click(reset_scores, outputs=[num1, num2, tot_scores, plot])
115
-
116
  with gr.Tab("Like or Dislike"):
117
  text_en = gr.Textbox(label="", value="en", visible=False)
118
  text_nl = gr.Textbox(label="", value="nl", visible=False)
119
 
120
  lang_selected = gr.Textbox(label="", value="", visible=False)
121
- num_selected = gr.Number(value=0, container=False, show_label=False, visible=False)
122
 
123
  with gr.Row():
124
  with gr.Column():
125
  with gr.Row():
126
  sample_button_en = gr.Button("Click to get a review in English.", size='sm')
127
  # gr.Markdown(''' <p style="text-align: center;"> or </p> ''')
128
- # gr.Markdown(''' <h2 style="text-align: center;"> or </h2> ''')
129
  sample_button_nl = gr.Button("Click to get a review in Dutch.", size='sm')
130
 
131
- # h1 = gr.HighlightedText(label="Review:", interactive=True, show_legend=True, combine_adjacent=False, color_map={"+": "red", "-": "green"})
132
-
133
  input_text = gr.Textbox(label="Review:", value="HELLO! Hallo!", visible=False, container=False)
134
  interpretation1 = gr.components.Interpretation(input_text)
135
 
136
- # image_1_1 = gr.Image('icon_user.png', height=80, width=80, min_width=80, show_label=False, show_share_button=False, interactive=False)
137
  slider_1_1 = gr.Slider(label="Human: Dislike β€”β€”> Like", container=True, min_width=200, height=80, show_label=True, interactive=True)
138
- # checkbox_1 = gr.CheckboxGroup(label="Which words are the guesses based on?", interactive=True)
139
- user_important = gr.Textbox(label="Which words are the guesses based on?", placeholder="Enter words that you think are important..")
140
 
141
  gr.Markdown(
142
  ''' ## Like or Dislike
@@ -149,34 +112,17 @@ Choose one of the three tasks below ... and start to play!
149
 
150
  * Step 3. Check the word highlighting to understand how AI made its decision.
151
  '''
152
- )
153
- # gr.Markdown(
154
- # ''' ## Like or Dislike
155
-
156
- # In this game, you will fight against AI in guessing the scores of the reviews:
157
-
158
- # * Step 1. Get an English/Dutch review and guess the corresponding score.
159
-
160
- # * Step 2. Check the score guessed by AI. The one with the correct/close answer wins.
161
-
162
- # * Step 3. (See how AI made the decision.)
163
-
164
- # Simple enough? Let's have fun!
165
- # '''
166
- # )
167
 
168
  with gr.Row():
169
  with gr.Column():
170
  chat_button_1 = gr.Button("Click to see AI's answer.", size='sm')
171
  slider_1_2 = gr.Slider(label="AI: Dislike β€”β€”> Like", container=True, min_width=200, height=80, show_label=True, interactive=True)
172
  interpre_button = gr.Button("See how AI gets the answer.", size='sm')
173
- # h2 = gr.HighlightedText(label="Review:", interactive=True, show_legend=True, combine_adjacent=False, color_map={"+": "red", "-": "green"})
174
  placeholder_text = gr.Textbox(label="Review:", value="HELLO! Hallo!", visible=False)
175
  interpretation2 = gr.components.Interpretation(placeholder_text)
176
- # image_1_2 = gr.Image('icon_robot.png', height=80, width=80, min_width=80, show_label=False, show_share_button=False, interactive=False)
177
  chatbot1 = gr.Chatbot(height=200, min_width=50, container=False) # height=300
178
  ####################################################################################################
179
- # gr.Markdown(''' --- ''')
180
  gr.Markdown(''' *** ''')
181
 
182
  gr.Markdown(
@@ -196,16 +142,12 @@ Choose one of the three tasks below ... and start to play!
196
  slider_1_4 = gr.Slider(label="AI: Dislike β€”β€”> Like", container=True, min_width=200, height=80, show_label=True, interactive=True)
197
  chatbot2 = gr.Chatbot(height=350, min_width=50, container=False) # height=300
198
 
199
- sample_button_en.click(read1, inputs=[text_en, num_selected], outputs=[interpretation1, lang_selected, num_selected])
200
- sample_button_nl.click(read1, inputs=[text_nl, num_selected], outputs=[interpretation1, lang_selected, num_selected])
201
- num_selected.change(reset_modules, outputs=[interpretation2, slider_1_1, slider_1_2, chatbot1, user_important])
202
- chat_button_1.click(func1, inputs=[lang_selected, num_selected, slider_1_1, num1, num2, user_important], outputs=[slider_1_2, chatbot1, num1, num2, tot_scores])
203
- interpre_button.click(interpre1, inputs=[lang_selected, num_selected], outputs=[interpretation2])
204
-
205
- # sample_button_en_written.click(read1_written, inputs=[text_en], outputs=[text_written])
206
- # sample_button_nl_written.click(read1_written, inputs=[text_nl], outputs=[text_written])
207
 
208
- # lang_written.change(fn=change_lang, inputs=radio, outputs=lang_written_text)
209
  chat_button_2.click(func1_written, inputs=[text_written, slider_1_3, lang_written], outputs=[interpretation4, slider_1_4, chatbot2])
210
 
211
  with gr.Tab("Human or Machine"):
@@ -213,11 +155,62 @@ Choose one of the three tasks below ... and start to play!
213
  text_input_2 = gr.Textbox()
214
  text_output_2 = gr.Label()
215
  text_button_2 = gr.Button("Check")
216
- with gr.Tab("Man or Woman"):
 
 
 
 
217
  with gr.Row():
218
- text_input_3 = gr.Textbox()
219
- text_output_3 = gr.Label()
220
- text_button_3 = gr.Button("Guess")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
 
223
 
 
71
 
72
  )
73
  with gr.Column():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  logo = gr.Image('logo.png', height=230, width=640, min_width=80, show_label=False, show_share_button=False, interactive=False, container=False)
75
 
76
  gr.Markdown(
 
81
  ''' ### <p style="text-align: center;"> Machine &ensp; ''' + str(int(0)) + ''' &ensp; VS &ensp; ''' + str(int(0)) + ''' &ensp; Human </p>'''
82
  )
83
 
 
 
 
 
 
 
 
 
 
 
84
  with gr.Tab("Like or Dislike"):
85
  text_en = gr.Textbox(label="", value="en", visible=False)
86
  text_nl = gr.Textbox(label="", value="nl", visible=False)
87
 
88
  lang_selected = gr.Textbox(label="", value="", visible=False)
89
+ num_selected_1 = gr.Number(value=0, container=False, show_label=False, visible=False)
90
 
91
  with gr.Row():
92
  with gr.Column():
93
  with gr.Row():
94
  sample_button_en = gr.Button("Click to get a review in English.", size='sm')
95
  # gr.Markdown(''' <p style="text-align: center;"> or </p> ''')
 
96
  sample_button_nl = gr.Button("Click to get a review in Dutch.", size='sm')
97
 
 
 
98
  input_text = gr.Textbox(label="Review:", value="HELLO! Hallo!", visible=False, container=False)
99
  interpretation1 = gr.components.Interpretation(input_text)
100
 
 
101
  slider_1_1 = gr.Slider(label="Human: Dislike β€”β€”> Like", container=True, min_width=200, height=80, show_label=True, interactive=True)
102
+ user_important = gr.Textbox(label="Which words are the guesses based on?", placeholder="Enter words that you think are important.")
 
103
 
104
  gr.Markdown(
105
  ''' ## Like or Dislike
 
112
 
113
  * Step 3. Check the word highlighting to understand how AI made its decision.
114
  '''
115
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  with gr.Row():
118
  with gr.Column():
119
  chat_button_1 = gr.Button("Click to see AI's answer.", size='sm')
120
  slider_1_2 = gr.Slider(label="AI: Dislike β€”β€”> Like", container=True, min_width=200, height=80, show_label=True, interactive=True)
121
  interpre_button = gr.Button("See how AI gets the answer.", size='sm')
 
122
  placeholder_text = gr.Textbox(label="Review:", value="HELLO! Hallo!", visible=False)
123
  interpretation2 = gr.components.Interpretation(placeholder_text)
 
124
  chatbot1 = gr.Chatbot(height=200, min_width=50, container=False) # height=300
125
  ####################################################################################################
 
126
  gr.Markdown(''' *** ''')
127
 
128
  gr.Markdown(
 
142
  slider_1_4 = gr.Slider(label="AI: Dislike β€”β€”> Like", container=True, min_width=200, height=80, show_label=True, interactive=True)
143
  chatbot2 = gr.Chatbot(height=350, min_width=50, container=False) # height=300
144
 
145
+ sample_button_en.click(read1, inputs=[text_en, num_selected_1], outputs=[interpretation1, lang_selected, num_selected_1])
146
+ sample_button_nl.click(read1, inputs=[text_nl, num_selected_1], outputs=[interpretation1, lang_selected, num_selected_1])
147
+ num_selected_1.change(reset_modules, outputs=[interpretation2, slider_1_1, slider_1_2, chatbot1, user_important])
148
+ chat_button_1.click(func1, inputs=[lang_selected, num_selected_1, slider_1_1, num1, num2, user_important], outputs=[slider_1_2, chatbot1, num1, num2, tot_scores])
149
+ interpre_button.click(interpre1, inputs=[lang_selected, num_selected_1], outputs=[interpretation2])
 
 
 
150
 
 
151
  chat_button_2.click(func1_written, inputs=[text_written, slider_1_3, lang_written], outputs=[interpretation4, slider_1_4, chatbot2])
152
 
153
  with gr.Tab("Human or Machine"):
 
155
  text_input_2 = gr.Textbox()
156
  text_output_2 = gr.Label()
157
  text_button_2 = gr.Button("Check")
158
+
159
+
160
+ with gr.Tab("Male or Female"):
161
+ num_selected_3 = gr.Number(value=0, container=False, show_label=False, visible=False)
162
+
163
  with gr.Row():
164
+ with gr.Column():
165
+ with gr.Row():
166
+ # gr.Markdown(''' <p style="text-align: center;"> or </p> ''')
167
+ sample_button_en_3 = gr.Button("Click to get a sentence.", size='sm')
168
+
169
+ input_text_mf = gr.Textbox(label="Sentence:", value="HELLO! Hallo!", visible=False, container=False)
170
+ interpretation_mf_1 = gr.components.Interpretation(input_text_mf)
171
+
172
+ slider_3_1 = gr.Slider(label="Human: Male β€”β€”> Female", container=True, min_width=200, height=80, show_label=True, interactive=True)
173
+ user_important_mf = gr.Textbox(label="Which words are the guesses based on?", placeholder="Enter words that you think are important.")
174
+
175
+ gr.Markdown(
176
+ ''' ## Male or Female
177
+
178
+ You're given a sentence spoken by a speaker.
179
+ The goal of this game is to guess the gender of the speaker, from 0 (=Male) to 100 (=Female).
180
+
181
+ * Step 1. Get a sentence and guess the gender of the speaker.
182
+
183
+ * Step 2. Check the score guessed by AI. Who gets the most correct answer wins.
184
+
185
+ * Step 3. Check the word highlighting to understand how AI made its decision.
186
+ '''
187
+ )
188
+
189
+ with gr.Row():
190
+ with gr.Column():
191
+ chat_button_mf = gr.Button("Click to see AI's answer.", size='sm')
192
+ slider_3_2 = gr.Slider(label="AI: Male β€”β€”> Female", container=True, min_width=200, height=80, show_label=True, interactive=True)
193
+ interpre_button_mf = gr.Button("See how AI gets the answer.", size='sm')
194
+ placeholder_text_mf = gr.Textbox(label="Sentence:", value="HELLO! Hallo!", visible=False)
195
+ interpretation_mf_2 = gr.components.Interpretation(placeholder_text)
196
+ chatbot_mf_1 = gr.Chatbot(height=200, min_width=50, container=False) # height=300
197
+ ####################################################################################################
198
+ gr.Markdown(''' *** ''')
199
+
200
+ gr.Markdown(
201
+ ''' # Now try your own reviews!
202
+ '''
203
+ )
204
+
205
+ with gr.Row():
206
+ with gr.Column():
207
+ text_written_mf = gr.Textbox(label="Sentence: ", placeholder="Enter your own sentence.", visible=True)
208
+ slider_3_3 = gr.Slider(label="Human: Male β€”β€”> Female", container=True, min_width=200, height=80, show_label=True, interactive=True)
209
+ chat_button_mf_2 = gr.Button("Click to see AI's answer.", size='sm')
210
+ placeholder_written_text_mf = gr.Textbox(label="Sentence: ", value="HELLO! Hallo!", visible=False)
211
+ interpretation_mf_4 = gr.components.Interpretation(placeholder_written_text)
212
+ slider_3_4 = gr.Slider(label="AI: Male β€”β€”> Female", container=True, min_width=200, height=80, show_label=True, interactive=True)
213
+ chatbot_mf_2 = gr.Chatbot(height=350, min_width=50, container=False) # height=300
214
 
215
 
216