Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import io
|
|
9 |
import os
|
10 |
from PIL import Image
|
11 |
import spaces
|
|
|
12 |
|
13 |
from diffusers import (
|
14 |
StableDiffusionPipeline,
|
@@ -30,12 +31,14 @@ qrcode_generator = qrcode.QRCode(
|
|
30 |
)
|
31 |
|
32 |
controlnet = ControlNetModel.from_pretrained(
|
33 |
-
"
|
|
|
|
|
34 |
).to("cuda")
|
35 |
|
36 |
pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
37 |
-
"digiplay/GhostMixV1.2VAE",
|
38 |
-
|
39 |
controlnet = controlnet,
|
40 |
torch_dtype = torch.float16,
|
41 |
safety_checker = None,
|
@@ -64,6 +67,26 @@ SAMPLER_MAP = {
|
|
64 |
"DEIS": lambda config: DEISMultistepScheduler.from_config(config),
|
65 |
}
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
@spaces.GPU()
|
68 |
def inference(
|
69 |
qr_code_content: str,
|
@@ -313,6 +336,24 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as blocks:
|
|
313 |
Enjoy the process of bringing your unique vision to life!
|
314 |
"""
|
315 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
run_btn.click(
|
317 |
inference,
|
318 |
inputs=[
|
|
|
9 |
import os
|
10 |
from PIL import Image
|
11 |
import spaces
|
12 |
+
import numpy as np
|
13 |
|
14 |
from diffusers import (
|
15 |
StableDiffusionPipeline,
|
|
|
31 |
)
|
32 |
|
33 |
controlnet = ControlNetModel.from_pretrained(
|
34 |
+
"monster-labs/control_v1p_sd15_qrcode_monster",
|
35 |
+
#"DionTimmer/controlnet_qrcode-control_v1p_sd15",
|
36 |
+
torch_dtype=torch.float16
|
37 |
).to("cuda")
|
38 |
|
39 |
pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
40 |
+
#"digiplay/GhostMixV1.2VAE",
|
41 |
+
"benjamin-paine/stable-diffusion-v1-5",
|
42 |
controlnet = controlnet,
|
43 |
torch_dtype = torch.float16,
|
44 |
safety_checker = None,
|
|
|
67 |
"DEIS": lambda config: DEISMultistepScheduler.from_config(config),
|
68 |
}
|
69 |
|
70 |
+
def scan_qr_code(image):
|
71 |
+
# Convert gradio image to PIL Image if necessary
|
72 |
+
if isinstance(image, np.ndarray):
|
73 |
+
image = Image.fromarray(image)
|
74 |
+
|
75 |
+
# Convert to grayscale
|
76 |
+
image = image.convert('L')
|
77 |
+
|
78 |
+
# Increase contrast
|
79 |
+
image = Image.eval(image, lambda x: 255 if x > 128 else 0)
|
80 |
+
|
81 |
+
# Try to decode the QR code
|
82 |
+
try:
|
83 |
+
qr = qrcode.QRCode()
|
84 |
+
qr.add_data('')
|
85 |
+
qr.decode(image)
|
86 |
+
return qr.data.decode('utf-8')
|
87 |
+
except Exception as e:
|
88 |
+
return None
|
89 |
+
|
90 |
@spaces.GPU()
|
91 |
def inference(
|
92 |
qr_code_content: str,
|
|
|
336 |
Enjoy the process of bringing your unique vision to life!
|
337 |
"""
|
338 |
)
|
339 |
+
|
340 |
+
def scan_and_display(image):
|
341 |
+
if image is None:
|
342 |
+
return "No image to scan"
|
343 |
+
|
344 |
+
scanned_text = scan_qr_code(image)
|
345 |
+
if scanned_text:
|
346 |
+
return f"Scanned successfully: {scanned_text}"
|
347 |
+
else:
|
348 |
+
return "Failed to scan QR code. Try adjusting the settings for better visibility."
|
349 |
+
|
350 |
+
scan_button.click(
|
351 |
+
scan_and_display,
|
352 |
+
inputs=[result_image],
|
353 |
+
outputs=[scan_result]
|
354 |
+
)
|
355 |
+
|
356 |
+
|
357 |
run_btn.click(
|
358 |
inference,
|
359 |
inputs=[
|