Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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(
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 431 |
|
| 432 |
record_button.click(
|
| 433 |
fn=record_participant,
|
| 434 |
inputs=[email_input, company_input, output_description, output_gallery],
|
| 435 |
-
outputs=
|
| 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 |
|