Spaces:
Running
Running
UI fix added example input
Browse files- app.py +33 -8
- examples/scribbles/detailed.png +0 -0
- examples/scribbles/test_purple_scarf.png +0 -0
- examples/scribbles/test_red_scarf.png +0 -0
- examples/sketch.png +0 -0
app.py
CHANGED
@@ -4,7 +4,10 @@ import numpy as np
|
|
4 |
from torchvision import transforms
|
5 |
from load_model import sample
|
6 |
import torch
|
|
|
7 |
import random
|
|
|
|
|
8 |
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
device = "mps" if torch.backends.mps.is_available() else device
|
@@ -12,6 +15,20 @@ device = "mps" if torch.backends.mps.is_available() else device
|
|
12 |
image_size = 128
|
13 |
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
transform = transforms.Compose(
|
16 |
[
|
17 |
transforms.Resize((image_size, image_size)),
|
@@ -60,12 +77,6 @@ with gr.Blocks(theme=theme) as demo:
|
|
60 |
|
61 |
with gr.Column():
|
62 |
output = gr.Image(type="pil", label="Output")
|
63 |
-
upscale_info = gr.Markdown(
|
64 |
-
"<p style='text-align: center; font-size: 12px;'>"
|
65 |
-
f"If you want to stretch the downloadable output, check the box below, the default output of neural networks is {image_size}x{image_size} "
|
66 |
-
"</p>"
|
67 |
-
)
|
68 |
-
upscale_button = gr.Checkbox(label="Stretch", value=False)
|
69 |
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
@@ -74,6 +85,11 @@ with gr.Blocks(theme=theme) as demo:
|
|
74 |
value=random.randint(0, 10000),
|
75 |
)
|
76 |
|
|
|
|
|
|
|
|
|
|
|
77 |
with gr.Column():
|
78 |
sampling_slider = gr.Slider(
|
79 |
minimum=1,
|
@@ -82,9 +98,10 @@ with gr.Blocks(theme=theme) as demo:
|
|
82 |
label="DDPM Sampling Steps π (the higher the number of steps the higher the quality of the images)",
|
83 |
value=50,
|
84 |
)
|
|
|
85 |
|
86 |
with gr.Row():
|
87 |
-
generate_button = gr.Button(value="
|
88 |
with gr.Row():
|
89 |
generate_info = gr.Markdown(
|
90 |
"<p style='text-align: center; font-size: 16px;'>"
|
@@ -92,6 +109,14 @@ with gr.Blocks(theme=theme) as demo:
|
|
92 |
"</p>"
|
93 |
)
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
generate_button.click(
|
96 |
process_images,
|
97 |
inputs=[
|
@@ -107,4 +132,4 @@ with gr.Blocks(theme=theme) as demo:
|
|
107 |
)
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
-
demo.
|
|
|
4 |
from torchvision import transforms
|
5 |
from load_model import sample
|
6 |
import torch
|
7 |
+
import glob
|
8 |
import random
|
9 |
+
import os
|
10 |
+
import pathlib
|
11 |
|
12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
13 |
device = "mps" if torch.backends.mps.is_available() else device
|
|
|
15 |
image_size = 128
|
16 |
|
17 |
|
18 |
+
def show_example_fn():
|
19 |
+
sketch = Image.open("examples/sketch.png")
|
20 |
+
scribble_folder = "./examples/scribbles/"
|
21 |
+
|
22 |
+
png_files = [f for f in os.listdir(scribble_folder) if f.lower().endswith(".png")]
|
23 |
+
|
24 |
+
# get random scribble
|
25 |
+
random_scribble = Image.open(
|
26 |
+
os.path.join(scribble_folder, random.choice(png_files))
|
27 |
+
)
|
28 |
+
|
29 |
+
return [sketch, random_scribble]
|
30 |
+
|
31 |
+
|
32 |
transform = transforms.Compose(
|
33 |
[
|
34 |
transforms.Resize((image_size, image_size)),
|
|
|
77 |
|
78 |
with gr.Column():
|
79 |
output = gr.Image(type="pil", label="Output")
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
with gr.Row():
|
82 |
with gr.Column():
|
|
|
85 |
value=random.randint(0, 10000),
|
86 |
)
|
87 |
|
88 |
+
upscale_button = gr.Checkbox(
|
89 |
+
label=f"Stretch (If you want to stretch the downloadable output, check the box below, the default output of neural networks is {image_size}x{image_size} )",
|
90 |
+
value=False,
|
91 |
+
)
|
92 |
+
|
93 |
with gr.Column():
|
94 |
sampling_slider = gr.Slider(
|
95 |
minimum=1,
|
|
|
98 |
label="DDPM Sampling Steps π (the higher the number of steps the higher the quality of the images)",
|
99 |
value=50,
|
100 |
)
|
101 |
+
show_example = gr.Button(value="Show Example Input ")
|
102 |
|
103 |
with gr.Row():
|
104 |
+
generate_button = gr.Button(value="Paint π¨ ")
|
105 |
with gr.Row():
|
106 |
generate_info = gr.Markdown(
|
107 |
"<p style='text-align: center; font-size: 16px;'>"
|
|
|
109 |
"</p>"
|
110 |
)
|
111 |
|
112 |
+
show_example.click(
|
113 |
+
show_example_fn,
|
114 |
+
inputs=[],
|
115 |
+
outputs=[sketch_input, scribbles_input],
|
116 |
+
concurrency_limit=1,
|
117 |
+
trigger_mode="once",
|
118 |
+
)
|
119 |
+
|
120 |
generate_button.click(
|
121 |
process_images,
|
122 |
inputs=[
|
|
|
132 |
)
|
133 |
|
134 |
if __name__ == "__main__":
|
135 |
+
demo.launch()
|
examples/scribbles/detailed.png
ADDED
![]() |
examples/scribbles/test_purple_scarf.png
ADDED
![]() |
examples/scribbles/test_red_scarf.png
ADDED
![]() |
examples/sketch.png
ADDED
![]() |