Kang Suhyun suhyun.kang commited on
Commit
af115bf
1 Parent(s): 17b1403

[#42] Hide vote buttons when generation fails (#50)

Browse files

Changes:
- Hide vote buttons when generation fails
- Update the generation failure message

Screenshot: https://screen.yanolja.in/mylSFgXusvrhUaxu.png

Co-authored-by: suhyun.kang <suhyun.kang@yanolja.group>

Files changed (2) hide show
  1. app.py +4 -5
  2. response.py +2 -2
app.py CHANGED
@@ -149,13 +149,12 @@ with gr.Blocks(title="Arena", css=css) as app:
149
  submit.click(
150
  fn=get_responses,
151
  inputs=[prompt, category_radio, source_language, target_language],
152
- outputs=response_boxes + model_names + [instruction_state]).then(
153
- fn=lambda: [gr.Button(interactive=True),
154
- gr.Row(visible=True)
155
  ] + [gr.Button(interactive=True) for _ in range(3)],
156
- outputs=[submit, vote_row] + vote_buttons)
 
157
 
158
- # TODO(#42): Hide vote buttons until response generation is successful.
159
  submit.click(fn=lambda: [
160
  gr.Button(interactive=False),
161
  gr.Row(visible=False),
 
149
  submit.click(
150
  fn=get_responses,
151
  inputs=[prompt, category_radio, source_language, target_language],
152
+ outputs=response_boxes + model_names + [instruction_state]).success(
153
+ fn=lambda: [gr.Row(visible=True)
 
154
  ] + [gr.Button(interactive=True) for _ in range(3)],
155
+ outputs=[vote_row] + vote_buttons).then(
156
+ fn=lambda: [gr.Button(interactive=True)], outputs=[submit])
157
 
 
158
  submit.click(fn=lambda: [
159
  gr.Button(interactive=False),
160
  gr.Row(visible=False),
response.py CHANGED
@@ -99,8 +99,8 @@ def get_responses(user_prompt, category, source_lang, target_lang):
99
 
100
  # TODO(#1): Narrow down the exception type.
101
  except Exception as e: # pylint: disable=broad-except
102
- print(f"Error in bot_response: {e}")
103
- raise e
104
 
105
  # It simulates concurrent stream response generation.
106
  max_response_length = max(len(response) for response in responses)
 
99
 
100
  # TODO(#1): Narrow down the exception type.
101
  except Exception as e: # pylint: disable=broad-except
102
+ print(f"Error with model {model}: {e}")
103
+ raise gr.Error("Failed to get response. Please try again.")
104
 
105
  # It simulates concurrent stream response generation.
106
  max_response_length = max(len(response) for response in responses)