Spaces:
Build error
Build error
Matt Blackman
commited on
Commit
•
f3f3a1d
1
Parent(s):
1174d66
Initial version
Browse files- Starry_Night.jpg +0 -0
- app.py +67 -0
- requirements.txt +5 -0
Starry_Night.jpg
ADDED
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import KandinskyPriorPipeline, KandinskyPipeline
|
4 |
+
import qrcode
|
5 |
+
|
6 |
+
IMAGE_WIDTH = 512
|
7 |
+
IMAGE_HEIGHT = 512
|
8 |
+
|
9 |
+
device = 0
|
10 |
+
if not torch.cuda.is_available():
|
11 |
+
print("GPU isn't available. Running on CPU.")
|
12 |
+
device = -1
|
13 |
+
|
14 |
+
pipe_prior = KandinskyPriorPipeline.from_pretrained(
|
15 |
+
"kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16
|
16 |
+
)
|
17 |
+
pipe_prior.to("cuda")
|
18 |
+
|
19 |
+
pipe = KandinskyPipeline.from_pretrained(
|
20 |
+
"kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
|
21 |
+
pipe.to("cuda")
|
22 |
+
|
23 |
+
|
24 |
+
def interpolate_image(qr_code_value, image, qr_image_weight, images_weight):
|
25 |
+
qr_code = qrcode.make(qr_code_value).resize((IMAGE_WIDTH, IMAGE_HEIGHT))
|
26 |
+
image_texts = [image, qr_code]
|
27 |
+
weights = [images_weight, qr_image_weight]
|
28 |
+
prompt = ""
|
29 |
+
prior_out = pipe_prior.interpolate(image_texts, weights)
|
30 |
+
|
31 |
+
result = pipe(prompt, **prior_out, height=IMAGE_HEIGHT, width=IMAGE_WIDTH)
|
32 |
+
|
33 |
+
return result.images
|
34 |
+
|
35 |
+
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
with gr.Row():
|
38 |
+
with gr.Column():
|
39 |
+
qr_input = gr.Text(label="QR Code Value")
|
40 |
+
image = gr.Image(label="Images", type="pil")
|
41 |
+
|
42 |
+
with gr.Row():
|
43 |
+
qr_image_weight = gr.Slider(
|
44 |
+
label="QR Image Weight", value=0.5, maximum=1)
|
45 |
+
images_weight = gr.Slider(
|
46 |
+
label="Input Images Weight", value=0.3, maximum=1)
|
47 |
+
|
48 |
+
submit_button = gr.Button("Submit")
|
49 |
+
|
50 |
+
with gr.Column():
|
51 |
+
output = gr.Gallery(label="Output")
|
52 |
+
output.style(grid=4)
|
53 |
+
|
54 |
+
submit_button.click(
|
55 |
+
fn=interpolate_image, inputs=[
|
56 |
+
qr_input, image, qr_image_weight, images_weight], outputs=output, api_name="interpolate"
|
57 |
+
)
|
58 |
+
|
59 |
+
gr.Examples(
|
60 |
+
examples=[["http://huggingface.co", "Starry_Night.jpg"]],
|
61 |
+
inputs=[qr_input, image],
|
62 |
+
outputs=output
|
63 |
+
)
|
64 |
+
|
65 |
+
|
66 |
+
demo.theme = gr.themes.Base()
|
67 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
diffusers
|
4 |
+
qrcode
|
5 |
+
PIL
|