Adam Jirkovsky commited on
Commit
8f52f69
·
1 Parent(s): e7bf219

Captcha functionality test

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -164,6 +164,12 @@ def generate_captcha(width=200, height=150, length=4):
164
  return image, text
165
 
166
 
 
 
 
 
 
 
167
 
168
  demo = gr.Blocks(css=custom_css)
169
  with demo:
@@ -335,6 +341,7 @@ with demo:
335
  #upload_button.upload(validate_upload, upload_button, file_input)
336
 
337
  with gr.Group():
 
338
  image, text = generate_captcha()
339
  captcha_img = gr.Image(
340
  image,
@@ -345,10 +352,12 @@ with demo:
345
  show_share_button=False,
346
  )
347
  captcha_input = gr.Textbox(placeholder="Enter the text in the image above", show_label=False, container=False)
348
- check_button = gr.Button("Check", interactive=True)
 
349
  check_button.click(
350
  fn = lambda: gr.alert("Correct!" if captcha_input.value == text else "Incorrect!"),
351
- inputs = [captcha_input],
 
352
  )
353
  submit_button = gr.Button("Submit Eval", interactive=True)
354
  submission_result = gr.Markdown()
 
164
  return image, text
165
 
166
 
167
+ def validate_captcha(input, text):
168
+ if input == text:
169
+ return True, "Correct!"
170
+ return False, "Incorrect! Please re-enter the code."
171
+
172
+
173
 
174
  demo = gr.Blocks(css=custom_css)
175
  with demo:
 
341
  #upload_button.upload(validate_upload, upload_button, file_input)
342
 
343
  with gr.Group():
344
+ captcha_correct = False
345
  image, text = generate_captcha()
346
  captcha_img = gr.Image(
347
  image,
 
352
  show_share_button=False,
353
  )
354
  captcha_input = gr.Textbox(placeholder="Enter the text in the image above", show_label=False, container=False)
355
+ check_button = gr.Button("Validate", interactive=True)
356
+ captcha_result = gr.Markdown()
357
  check_button.click(
358
  fn = lambda: gr.alert("Correct!" if captcha_input.value == text else "Incorrect!"),
359
+ inputs = [captcha_input, text],
360
+ outputs = [captcha_correct, captcha_result],
361
  )
362
  submit_button = gr.Button("Submit Eval", interactive=True)
363
  submission_result = gr.Markdown()