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