Spaces:
Sleeping
Sleeping
Kvikontent
commited on
Commit
•
475db54
1
Parent(s):
589d259
Update app.py
Browse files
app.py
CHANGED
@@ -2,29 +2,35 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import qrcode
|
4 |
import io
|
5 |
-
from PIL import Image
|
6 |
|
7 |
import os
|
8 |
|
9 |
# Get the Hugging Face API token from the environment variable
|
10 |
hf_token = os.environ.get("hf_token")
|
11 |
|
12 |
-
# Function to generate a QR code
|
13 |
def generate_qr_image(url, image_size):
|
|
|
|
|
|
|
|
|
|
|
14 |
qr = qrcode.QRCode(
|
15 |
version=1,
|
16 |
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
17 |
-
box_size=
|
18 |
-
border=
|
19 |
)
|
20 |
qr.add_data(url)
|
21 |
qr.make(fit=True)
|
22 |
|
23 |
-
qr_img = qr.make_image(fill_color="black", back_color=
|
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
|
29 |
def query_image(text):
|
30 |
API_URL = "https://api-inference.huggingface.co/models/goofyai/3d_render_style_xl"
|
@@ -40,7 +46,7 @@ def generate_image(url, text):
|
|
40 |
api_image = Image.open(io.BytesIO(image_bytes))
|
41 |
|
42 |
# Generate QR code image
|
43 |
-
qr_image = generate_qr_image(url,
|
44 |
|
45 |
# Create a blank image with transparency
|
46 |
final_image = Image.new('RGBA', api_image.size, (255, 255, 255, 0))
|
|
|
2 |
import requests
|
3 |
import qrcode
|
4 |
import io
|
5 |
+
from PIL import Image
|
6 |
|
7 |
import os
|
8 |
|
9 |
# Get the Hugging Face API token from the environment variable
|
10 |
hf_token = os.environ.get("hf_token")
|
11 |
|
12 |
+
# Function to generate a QR code with transparent fill color
|
13 |
def generate_qr_image(url, image_size):
|
14 |
+
# Determine box size based on the larger dimension of the image
|
15 |
+
max_dim = max(image_size[0], image_size[1])
|
16 |
+
box_size = max_dim // 25
|
17 |
+
border = 1
|
18 |
+
|
19 |
qr = qrcode.QRCode(
|
20 |
version=1,
|
21 |
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
22 |
+
box_size=box_size,
|
23 |
+
border=border,
|
24 |
)
|
25 |
qr.add_data(url)
|
26 |
qr.make(fit=True)
|
27 |
|
28 |
+
qr_img = qr.make_image(fill_color="black", back_color=None).convert("RGBA")
|
29 |
qr_img = qr_img.resize(image_size)
|
30 |
|
31 |
return qr_img
|
32 |
|
33 |
+
|
34 |
# Function to query the image from the Hugging Face API
|
35 |
def query_image(text):
|
36 |
API_URL = "https://api-inference.huggingface.co/models/goofyai/3d_render_style_xl"
|
|
|
46 |
api_image = Image.open(io.BytesIO(image_bytes))
|
47 |
|
48 |
# Generate QR code image
|
49 |
+
qr_image = generate_qr_image(url, api_image.size)
|
50 |
|
51 |
# Create a blank image with transparency
|
52 |
final_image = Image.new('RGBA', api_image.size, (255, 255, 255, 0))
|