Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,49 +16,46 @@ def generate_upi_qr(upi_code, amount, merchant_name=None):
|
|
16 |
qr.make(fit=True)
|
17 |
qr_image = qr.make_image(fill="black", back_color="white").convert("RGB")
|
18 |
|
19 |
-
# Generate unique image name based on UPI ID, amount, and timestamp
|
20 |
-
timestamp = str(int(time.time()))
|
21 |
-
image_name = f"qr_{upi_code}_{amount}_{timestamp}.png"
|
22 |
|
23 |
-
# Load your template
|
24 |
-
template = Image.open(gradio.interface.assets.get("Asset 6-1.png")).convert("RGB")
|
25 |
|
26 |
-
# Resize the QR code if needed
|
27 |
-
qr_image = qr_image.resize((700, 700))
|
28 |
|
29 |
-
# Paste the QR code onto your template
|
30 |
-
template.paste(qr_image, (225, 450))
|
31 |
|
32 |
-
# Draw text for amount and merchant name
|
33 |
-
draw = ImageDraw.Draw(template)
|
34 |
-
font = ImageFont.truetype("arial.ttf", 50) # Specify the font file and size
|
35 |
|
36 |
-
text_amount = f"Amount: {amount} INR"
|
37 |
-
text_merchant = f"Merchant: {merchant_name}"
|
38 |
|
39 |
-
w_amount, h_amount = draw.textsize(text_amount, font=font)
|
40 |
-
w_merchant, h_merchant = draw.textsize(text_merchant, font=font)
|
41 |
|
42 |
-
width, height = template.size
|
43 |
|
44 |
-
position_amount = ((width - w_amount) // 2, height - 1145) # Adjust the height as needed
|
45 |
-
position_merchant = ((width - w_merchant) // 2, height - 1205) # Adjust the height as needed
|
46 |
|
47 |
-
draw.text(position_amount, text_amount, (0, 0, 0), font=font)
|
48 |
-
draw.text(position_merchant, text_merchant, (0, 0, 0), font=font)
|
49 |
|
50 |
-
# Save the result
|
51 |
-
final_image_path = os.path.join('static', 'qr_images', f'final_{image_name}')
|
52 |
-
template.save(final_image_path)
|
53 |
|
54 |
-
return
|
55 |
|
56 |
-
def generate_upi_qr_interface(upi_code, amount, merchant_name=None):
|
57 |
-
image_path = generate_upi_qr(upi_code, amount, merchant_name)
|
58 |
-
return image_path
|
59 |
|
60 |
iface = gr.Interface(
|
61 |
-
fn=
|
62 |
inputs=["text", "text", "text"],
|
63 |
outputs="image",
|
64 |
title="Generate UPI QR Code",
|
|
|
16 |
qr.make(fit=True)
|
17 |
qr_image = qr.make_image(fill="black", back_color="white").convert("RGB")
|
18 |
|
19 |
+
# # Generate unique image name based on UPI ID, amount, and timestamp
|
20 |
+
# timestamp = str(int(time.time()))
|
21 |
+
# image_name = f"qr_{upi_code}_{amount}_{timestamp}.png"
|
22 |
|
23 |
+
# # Load your template
|
24 |
+
# template = Image.open(gradio.interface.assets.get("Asset 6-1.png")).convert("RGB")
|
25 |
|
26 |
+
# # Resize the QR code if needed
|
27 |
+
# qr_image = qr_image.resize((700, 700))
|
28 |
|
29 |
+
# # Paste the QR code onto your template
|
30 |
+
# template.paste(qr_image, (225, 450))
|
31 |
|
32 |
+
# # Draw text for amount and merchant name
|
33 |
+
# draw = ImageDraw.Draw(template)
|
34 |
+
# font = ImageFont.truetype("arial.ttf", 50) # Specify the font file and size
|
35 |
|
36 |
+
# text_amount = f"Amount: {amount} INR"
|
37 |
+
# text_merchant = f"Merchant: {merchant_name}"
|
38 |
|
39 |
+
# w_amount, h_amount = draw.textsize(text_amount, font=font)
|
40 |
+
# w_merchant, h_merchant = draw.textsize(text_merchant, font=font)
|
41 |
|
42 |
+
# width, height = template.size
|
43 |
|
44 |
+
# position_amount = ((width - w_amount) // 2, height - 1145) # Adjust the height as needed
|
45 |
+
# position_merchant = ((width - w_merchant) // 2, height - 1205) # Adjust the height as needed
|
46 |
|
47 |
+
# draw.text(position_amount, text_amount, (0, 0, 0), font=font)
|
48 |
+
# draw.text(position_merchant, text_merchant, (0, 0, 0), font=font)
|
49 |
|
50 |
+
# # Save the result
|
51 |
+
# final_image_path = os.path.join('static', 'qr_images', f'final_{image_name}')
|
52 |
+
# template.save(final_image_path)
|
53 |
|
54 |
+
return qr_image
|
55 |
|
|
|
|
|
|
|
56 |
|
57 |
iface = gr.Interface(
|
58 |
+
fn=generate_upi_qr,
|
59 |
inputs=["text", "text", "text"],
|
60 |
outputs="image",
|
61 |
title="Generate UPI QR Code",
|