liujch1998 commited on
Commit
f8a5c23
Β·
1 Parent(s): 8b35b55
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -92,7 +92,7 @@ def predict(statement, do_save=True):
92
  print('Commit URL:', commit_url)
93
  print(output_raw)
94
  print()
95
- return output, output_raw
96
 
97
  def record_feedback(output_raw, feedback, do_save=True):
98
  if do_save:
@@ -105,6 +105,7 @@ def record_feedback(output_raw, feedback, do_save=True):
105
  print('Commit URL:', commit_url)
106
  print(output_raw)
107
  print()
 
108
  def record_feedback_agree(output_raw, do_save=True):
109
  record_feedback(output_raw, 'agree', do_save)
110
  def record_feedback_disagree(output_raw, do_save=True):
@@ -198,30 +199,31 @@ with gr.Blocks() as demo:
198
  '''
199
  )
200
  with gr.Row():
201
- with gr.Column(scale=1):
202
  do_save = gr.Checkbox(
203
  value=True,
204
  label="Store data",
205
  info="You agree to the storage of your input data for research and development purposes:")
206
- statement = gr.Textbox(placeholder='Enter a commonsense statement here', label='Statement')
207
- submit = gr.Button(value='Submit', variant='primary')
208
  with gr.Column(scale=1):
209
- output = gr.outputs.Label(num_top_classes=2)
210
  output_raw = gr.JSON(visible=True)
211
  with gr.Row():
212
- feedback_agree = gr.Button(value='πŸ‘ Agree', variant='secondary')
213
- feedback_disagree = gr.Button(value='πŸ‘Ž Disagree', variant='secondary')
 
214
  with gr.Row():
215
  gr.Examples(
216
  examples=examples,
217
  inputs=[statement],
218
  cache_examples=False,
219
  fn=predict,
220
- outputs=[output, output_raw],
221
  )
222
- submit.click(predict, inputs=[statement, do_save], outputs=[output, output_raw])
223
  # statement.submit(predict, inputs=[statement], outputs=[output, output_raw])
224
- feedback_agree.click(record_feedback_agree, inputs=[output_raw, do_save])
225
- feedback_disagree.click(record_feedback_disagree, inputs=[output_raw, do_save])
226
 
227
  demo.queue(concurrency_count=16).launch(debug=True)
 
92
  print('Commit URL:', commit_url)
93
  print(output_raw)
94
  print()
95
+ return output, output_raw, gr.update(interactive=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False)
96
 
97
  def record_feedback(output_raw, feedback, do_save=True):
98
  if do_save:
 
105
  print('Commit URL:', commit_url)
106
  print(output_raw)
107
  print()
108
+ return gr.update(interactive=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
109
  def record_feedback_agree(output_raw, do_save=True):
110
  record_feedback(output_raw, 'agree', do_save)
111
  def record_feedback_disagree(output_raw, do_save=True):
 
199
  '''
200
  )
201
  with gr.Row():
202
+ with gr.Column(scale=2):
203
  do_save = gr.Checkbox(
204
  value=True,
205
  label="Store data",
206
  info="You agree to the storage of your input data for research and development purposes:")
207
+ statement = gr.Textbox(placeholder='Enter a commonsense statement here', label='Statement', interactive=True)
208
+ submit = gr.Button(value='Submit', variant='primary', visible=True)
209
  with gr.Column(scale=1):
210
+ output = gr.Label(num_top_classes=2, interactive=False)
211
  output_raw = gr.JSON(visible=True)
212
  with gr.Row():
213
+ feedback_agree = gr.Button(value='πŸ‘ Agree', variant='secondary', visible=False)
214
+ feedback_disagree = gr.Button(value='πŸ‘Ž Disagree', variant='secondary', visible=False)
215
+ feedback_ack = gr.Markdown(value='Thanks for your feedback!', visible=False, interactive=False)
216
  with gr.Row():
217
  gr.Examples(
218
  examples=examples,
219
  inputs=[statement],
220
  cache_examples=False,
221
  fn=predict,
222
+ outputs=[output, output_raw, statement, submit, feedback_agree, feedback_disagree, feedback_ack],
223
  )
224
+ submit.click(predict, inputs=[statement, do_save], outputs=[output, output_raw, statement, submit, feedback_agree, feedback_disagree, feedback_ack])
225
  # statement.submit(predict, inputs=[statement], outputs=[output, output_raw])
226
+ feedback_agree.click(record_feedback_agree, inputs=[output_raw, do_save], outputs=[statement, submit, feedback_agree, feedback_disagree, feedback_ack])
227
+ feedback_disagree.click(record_feedback_disagree, inputs=[output_raw, do_save], outputs=[statement, submit, feedback_agree, feedback_disagree, feedback_ack])
228
 
229
  demo.queue(concurrency_count=16).launch(debug=True)