Pash1986 commited on
Commit
c2a6728
1 Parent(s): e6a22dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -28
app.py CHANGED
@@ -301,7 +301,7 @@ def create_pdf(images, description, email, company):
301
  c.save()
302
 
303
 
304
- return filename
305
 
306
 
307
  # Function to generate image description using Claude 3 Sonnet
@@ -370,26 +370,32 @@ def start_image_search(image, text):
370
  description = generate_image_description_with_claude(images_base64_strs, img_base64_str)
371
  return images, description
372
 
373
- def generate_qr_code(url):
374
- # Generate QR code
375
- qr = qrcode.QRCode(
376
- version=1,
377
- error_correction=qrcode.constants.ERROR_CORRECT_L,
378
- box_size=10,
379
- border=4,
380
- )
381
- qr.add_data(url)
382
- qr.make(fit=True)
383
-
384
- img_qr = qr.make_image(fill_color="black", back_color="white")
 
 
 
385
 
386
- # Convert PIL Image to bytes for displaying or saving
387
- img_byte_arr = io.BytesIO()
388
- img_qr.save(img_byte_arr, format='PNG')
389
- img_byte_arr = img_byte_arr.getvalue()
390
 
391
- return img_byte_arr
 
 
 
392
 
 
 
 
393
 
394
  with gr.Blocks() as demo:
395
 
@@ -427,22 +433,14 @@ with gr.Blocks() as demo:
427
  outputs=[output_gallery, output_description]
428
  )
429
 
430
- pdf_file=gr.File(label="Download Search Results as PDF")
431
 
432
  record_button.click(
433
  fn=record_participant,
434
  inputs=[email_input, company_input, output_description, output_gallery],
435
- outputs=pdf_file
436
  )
437
 
438
- gr.Interface(
439
- generate_qr_code,
440
- inputs=pdf_file,
441
- outputs=gr.Image(type="numpy", label="Generated QR Code"),
442
- title="Filename to QR Code Generator",
443
- description="Enter the filename to generate its QR code"
444
- )
445
-
446
  with gr.Tab("Code"):
447
  gr.Code(label="Code", language="python", value=fetch_url_data('https://huggingface.co/spaces/MongoDB/aws-bedrock-celeb-matcher/raw/main/app.py'))
448
 
 
301
  c.save()
302
 
303
 
304
+ return generate_qr_code(filename)
305
 
306
 
307
  # Function to generate image description using Claude 3 Sonnet
 
370
  description = generate_image_description_with_claude(images_base64_strs, img_base64_str)
371
  return images, description
372
 
373
+ def generate_qr_code(filename):
374
+ try:
375
+ # Read the content of the file
376
+ with open(filename, 'rb') as file:
377
+ file_content = file.read()
378
+
379
+ # Generate QR code
380
+ qr = qrcode.QRCode(
381
+ version=1,
382
+ error_correction=qrcode.constants.ERROR_CORRECT_L,
383
+ box_size=10,
384
+ border=4,
385
+ )
386
+ qr.add_data(file_content)
387
+ qr.make(fit=True)
388
 
389
+ img_qr = qr.make_image(fill_color="black", back_color="white")
 
 
 
390
 
391
+ # Convert PIL Image to bytes for Gradio output
392
+ img_byte_arr = io.BytesIO()
393
+ img_qr.save(img_byte_arr, format='PNG')
394
+ img_byte_arr = img_byte_arr.getvalue()
395
 
396
+ return img_byte_arr
397
+ except Exception as e:
398
+ return f"Error: {e}"
399
 
400
  with gr.Blocks() as demo:
401
 
 
433
  outputs=[output_gallery, output_description]
434
  )
435
 
436
+
437
 
438
  record_button.click(
439
  fn=record_participant,
440
  inputs=[email_input, company_input, output_description, output_gallery],
441
+ outputs=gr.Image(type="numpy", label="Generated QR Code")
442
  )
443
 
 
 
 
 
 
 
 
 
444
  with gr.Tab("Code"):
445
  gr.Code(label="Code", language="python", value=fetch_url_data('https://huggingface.co/spaces/MongoDB/aws-bedrock-celeb-matcher/raw/main/app.py'))
446