Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,11 +20,9 @@ def generate_qr_image(url, image_size):
|
|
20 |
qr.add_data(url)
|
21 |
qr.make(fit=True)
|
22 |
|
23 |
-
qr_img = qr.make_image(fill_color="black", back_color="white")
|
24 |
-
qr_img = qr_img.convert("RGBA")
|
25 |
-
|
26 |
qr_img = qr_img.resize(image_size)
|
27 |
-
|
28 |
return qr_img
|
29 |
|
30 |
# Function to query the image from the Hugging Face API
|
@@ -39,14 +37,21 @@ def query_image(text):
|
|
39 |
def generate_image(url, text):
|
40 |
# Generate image from Hugging Face API
|
41 |
image_bytes = query_image(text)
|
42 |
-
api_image = Image.open(io.BytesIO(image_bytes))
|
43 |
-
|
44 |
# Generate QR code image
|
45 |
-
qr_image = generate_qr_image(url,
|
46 |
-
|
47 |
-
#
|
48 |
-
final_image = Image.
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
return final_image
|
51 |
|
52 |
# Inputs and outputs for Gradio interface
|
|
|
20 |
qr.add_data(url)
|
21 |
qr.make(fit=True)
|
22 |
|
23 |
+
qr_img = qr.make_image(fill_color="black", back_color="white").convert("RGBA")
|
|
|
|
|
24 |
qr_img = qr_img.resize(image_size)
|
25 |
+
|
26 |
return qr_img
|
27 |
|
28 |
# Function to query the image from the Hugging Face API
|
|
|
37 |
def generate_image(url, text):
|
38 |
# Generate image from Hugging Face API
|
39 |
image_bytes = query_image(text)
|
40 |
+
api_image = Image.open(io.BytesIO(image_bytes))
|
41 |
+
|
42 |
# Generate QR code image
|
43 |
+
qr_image = generate_qr_image(url, (250, 250))
|
44 |
+
|
45 |
+
# Create a blank image with transparency
|
46 |
+
final_image = Image.new('RGBA', api_image.size, (255, 255, 255, 0))
|
47 |
+
|
48 |
+
# Position the QR code in the image
|
49 |
+
qr_position = ((final_image.width - qr_image.width) // 2, (final_image.height - qr_image.height) // 2)
|
50 |
+
final_image.paste(qr_image, qr_position, qr_image)
|
51 |
+
|
52 |
+
# Composite the API image and the final image with the QR code
|
53 |
+
final_image = Image.alpha_composite(api_image.convert("RGBA"), final_image)
|
54 |
+
|
55 |
return final_image
|
56 |
|
57 |
# Inputs and outputs for Gradio interface
|