Adam Jirkovsky commited on
Commit
7be7cf3
·
1 Parent(s): 8df3646

Captcha update

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -156,6 +156,14 @@ def validate_upload(input):
156
  raise gr.Error("Cannot parse file")
157
 
158
 
 
 
 
 
 
 
 
 
159
 
160
  demo = gr.Blocks(css=custom_css)
161
  with demo:
@@ -351,10 +359,7 @@ with demo:
351
  )
352
  base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
353
  """
354
- captcha_text = ''.join(random.choices(string.ascii_uppercase + string.digits, k=4))
355
- captcha_obj = ImageCaptcha(200, 150)
356
- captcha_data = captcha_obj.generate("1234")
357
- image = Image.open(captcha_data)
358
  captcha_img = gr.Image(
359
  image,
360
  container=False,
@@ -362,6 +367,7 @@ with demo:
362
  show_fullscreen_button=False,
363
  show_share_button=False,
364
  )
 
365
  submit_button = gr.Button("Submit Eval", interactive=True)
366
  submission_result = gr.Markdown()
367
  submit_button.click(
 
156
  raise gr.Error("Cannot parse file")
157
 
158
 
159
+ def generate_captcha(width=200, height=150, length=4):
160
+ text = ''.join(random.choices(string.ascii_uppercase + string.digits, k=length))
161
+ captcha_obj = ImageCaptcha(width, height)
162
+ data = captcha_obj.generate(text)
163
+ image = Image.open(data)
164
+ return image, text
165
+
166
+
167
 
168
  demo = gr.Blocks(css=custom_css)
169
  with demo:
 
359
  )
360
  base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
361
  """
362
+ image, text = generate_captcha()
 
 
 
363
  captcha_img = gr.Image(
364
  image,
365
  container=False,
 
367
  show_fullscreen_button=False,
368
  show_share_button=False,
369
  )
370
+ captcha_input = gr.Textbox(placeholder="Enter the text in the image above")
371
  submit_button = gr.Button("Submit Eval", interactive=True)
372
  submission_result = gr.Markdown()
373
  submit_button.click(