Spaces:
Runtime error
Runtime error
Adapt information
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import numpy as np
|
|
| 3 |
import time
|
| 4 |
import math
|
| 5 |
import random
|
| 6 |
-
import imageio
|
| 7 |
import torch
|
| 8 |
|
| 9 |
from diffusers import AutoPipelineForImage2Image
|
|
@@ -11,9 +10,15 @@ from PIL import Image, ImageFilter
|
|
| 11 |
|
| 12 |
max_64_bit_int = 2**63 - 1
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
pipe = AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype = floatType, variant = variant)
|
| 19 |
pipe = pipe.to(device)
|
|
@@ -24,9 +29,7 @@ def update_seed(is_randomize_seed, seed):
|
|
| 24 |
return seed
|
| 25 |
|
| 26 |
def toggle_debug(is_debug_mode):
|
| 27 |
-
|
| 28 |
-
return [gr.update(visible = True)]
|
| 29 |
-
return [gr.update(visible = False)]
|
| 30 |
|
| 31 |
def check(
|
| 32 |
source_img,
|
|
@@ -38,6 +41,7 @@ def check(
|
|
| 38 |
strength,
|
| 39 |
denoising_steps,
|
| 40 |
seed,
|
|
|
|
| 41 |
debug_mode,
|
| 42 |
progress = gr.Progress()
|
| 43 |
):
|
|
@@ -56,6 +60,7 @@ def redraw(
|
|
| 56 |
image_guidance_scale,
|
| 57 |
strength,
|
| 58 |
denoising_steps,
|
|
|
|
| 59 |
seed,
|
| 60 |
debug_mode,
|
| 61 |
progress = gr.Progress()
|
|
@@ -69,6 +74,7 @@ def redraw(
|
|
| 69 |
image_guidance_scale,
|
| 70 |
strength,
|
| 71 |
denoising_steps,
|
|
|
|
| 72 |
seed,
|
| 73 |
debug_mode
|
| 74 |
)
|
|
@@ -163,7 +169,7 @@ def redraw(
|
|
| 163 |
minutes = minutes - (hours * 60)
|
| 164 |
return [
|
| 165 |
output_image,
|
| 166 |
-
"Start again to get a different result. The new image is " + str(output_width) + " pixels large and " + str(output_height) + " pixels high, so an image of " + f'{output_width * output_height:,}' + " pixels. The image have been generated in " + str(hours) + " h, " + str(minutes) + " min, " + str(secondes) + " sec." + limitation,
|
| 167 |
input_image
|
| 168 |
]
|
| 169 |
|
|
@@ -174,7 +180,7 @@ with gr.Blocks() as interface:
|
|
| 174 |
<p style="text-align: center;">Modifies the global render of your image, at any resolution, freely, without account, without watermark, without installation, which can be downloaded</p>
|
| 175 |
<br/>
|
| 176 |
<br/>
|
| 177 |
-
|
| 178 |
<br/>
|
| 179 |
<ul>
|
| 180 |
<li>To change the <b>view angle</b> of your image, I recommend to use <i>Zero123</i>,</li>
|
|
@@ -195,7 +201,7 @@ with gr.Blocks() as interface:
|
|
| 195 |
)
|
| 196 |
with gr.Column():
|
| 197 |
source_img = gr.Image(label = "Your image", sources = ["upload", "webcam", "clipboard"], type = "pil")
|
| 198 |
-
prompt = gr.Textbox(label = "Prompt", info = "Describe the subject, the background and the style of image; 77 token limit", placeholder = "Describe what you want to see")
|
| 199 |
strength = gr.Slider(value = 0.5, minimum = 0.01, maximum = 1.0, step = 0.01, label = "Strength", info = "lower=follow the original image, higher=follow the prompt")
|
| 200 |
with gr.Accordion("Advanced options", open = False):
|
| 201 |
negative_prompt = gr.Textbox(label = "Negative prompt", placeholder = "Describe what you do NOT want to see", value = "Ugly, malformed, noise, blur, watermark")
|
|
@@ -207,14 +213,15 @@ with gr.Blocks() as interface:
|
|
| 207 |
seed = gr.Slider(minimum = 0, maximum = max_64_bit_int, step = 1, randomize = True, label = "Seed")
|
| 208 |
debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
|
| 209 |
|
| 210 |
-
submit = gr.Button("Redraw", variant = "primary")
|
| 211 |
|
| 212 |
redrawn_image = gr.Image(label = "Redrawn image")
|
| 213 |
information = gr.Label(label = "Information")
|
| 214 |
original_image = gr.Image(label = "Original image", visible = False)
|
| 215 |
|
| 216 |
submit.click(update_seed, inputs = [
|
| 217 |
-
randomize_seed,
|
|
|
|
| 218 |
], outputs = [
|
| 219 |
seed
|
| 220 |
], queue = False, show_progress = False).then(toggle_debug, debug_mode, [
|
|
@@ -228,6 +235,7 @@ with gr.Blocks() as interface:
|
|
| 228 |
image_guidance_scale,
|
| 229 |
strength,
|
| 230 |
denoising_steps,
|
|
|
|
| 231 |
seed,
|
| 232 |
debug_mode
|
| 233 |
], outputs = [], queue = False, show_progress = False).success(redraw, inputs = [
|
|
@@ -239,6 +247,7 @@ with gr.Blocks() as interface:
|
|
| 239 |
image_guidance_scale,
|
| 240 |
strength,
|
| 241 |
denoising_steps,
|
|
|
|
| 242 |
seed,
|
| 243 |
debug_mode
|
| 244 |
], outputs = [
|
|
@@ -258,6 +267,7 @@ with gr.Blocks() as interface:
|
|
| 258 |
image_guidance_scale,
|
| 259 |
strength,
|
| 260 |
denoising_steps,
|
|
|
|
| 261 |
seed,
|
| 262 |
debug_mode
|
| 263 |
],
|
|
@@ -276,6 +286,7 @@ with gr.Blocks() as interface:
|
|
| 276 |
1.1,
|
| 277 |
0.6,
|
| 278 |
1000,
|
|
|
|
| 279 |
42,
|
| 280 |
False
|
| 281 |
],
|
|
|
|
| 3 |
import time
|
| 4 |
import math
|
| 5 |
import random
|
|
|
|
| 6 |
import torch
|
| 7 |
|
| 8 |
from diffusers import AutoPipelineForImage2Image
|
|
|
|
| 10 |
|
| 11 |
max_64_bit_int = 2**63 - 1
|
| 12 |
|
| 13 |
+
# Automatic device detection
|
| 14 |
+
if torch.cuda.is_available():
|
| 15 |
+
device = "cuda"
|
| 16 |
+
floatType = torch.float16
|
| 17 |
+
variant = "fp16"
|
| 18 |
+
else:
|
| 19 |
+
device = "cpu"
|
| 20 |
+
floatType = torch.float32
|
| 21 |
+
variant = None
|
| 22 |
|
| 23 |
pipe = AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype = floatType, variant = variant)
|
| 24 |
pipe = pipe.to(device)
|
|
|
|
| 29 |
return seed
|
| 30 |
|
| 31 |
def toggle_debug(is_debug_mode):
|
| 32 |
+
return [gr.update(visible = is_debug_mode)]
|
|
|
|
|
|
|
| 33 |
|
| 34 |
def check(
|
| 35 |
source_img,
|
|
|
|
| 41 |
strength,
|
| 42 |
denoising_steps,
|
| 43 |
seed,
|
| 44 |
+
is_randomize_seed,
|
| 45 |
debug_mode,
|
| 46 |
progress = gr.Progress()
|
| 47 |
):
|
|
|
|
| 60 |
image_guidance_scale,
|
| 61 |
strength,
|
| 62 |
denoising_steps,
|
| 63 |
+
is_randomize_seed,
|
| 64 |
seed,
|
| 65 |
debug_mode,
|
| 66 |
progress = gr.Progress()
|
|
|
|
| 74 |
image_guidance_scale,
|
| 75 |
strength,
|
| 76 |
denoising_steps,
|
| 77 |
+
is_randomize_seed,
|
| 78 |
seed,
|
| 79 |
debug_mode
|
| 80 |
)
|
|
|
|
| 169 |
minutes = minutes - (hours * 60)
|
| 170 |
return [
|
| 171 |
output_image,
|
| 172 |
+
("Start again to get a different result. " if is_randomize_seed else "") + "The new image is " + str(output_width) + " pixels large and " + str(output_height) + " pixels high, so an image of " + f'{output_width * output_height:,}' + " pixels. The image have been generated in " + str(hours) + " h, " + str(minutes) + " min, " + str(secondes) + " sec." + limitation,
|
| 173 |
input_image
|
| 174 |
]
|
| 175 |
|
|
|
|
| 180 |
<p style="text-align: center;">Modifies the global render of your image, at any resolution, freely, without account, without watermark, without installation, which can be downloaded</p>
|
| 181 |
<br/>
|
| 182 |
<br/>
|
| 183 |
+
✨ Powered by <i>SDXL Turbo</i> artificial intellingence. For illustration purpose, not information purpose. The new content is not based on real information but imagination.
|
| 184 |
<br/>
|
| 185 |
<ul>
|
| 186 |
<li>To change the <b>view angle</b> of your image, I recommend to use <i>Zero123</i>,</li>
|
|
|
|
| 201 |
)
|
| 202 |
with gr.Column():
|
| 203 |
source_img = gr.Image(label = "Your image", sources = ["upload", "webcam", "clipboard"], type = "pil")
|
| 204 |
+
prompt = gr.Textbox(label = "Prompt", info = "Describe the subject, the background and the style of image; 77 token limit", placeholder = "Describe what you want to see", lines = 2)
|
| 205 |
strength = gr.Slider(value = 0.5, minimum = 0.01, maximum = 1.0, step = 0.01, label = "Strength", info = "lower=follow the original image, higher=follow the prompt")
|
| 206 |
with gr.Accordion("Advanced options", open = False):
|
| 207 |
negative_prompt = gr.Textbox(label = "Negative prompt", placeholder = "Describe what you do NOT want to see", value = "Ugly, malformed, noise, blur, watermark")
|
|
|
|
| 213 |
seed = gr.Slider(minimum = 0, maximum = max_64_bit_int, step = 1, randomize = True, label = "Seed")
|
| 214 |
debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
|
| 215 |
|
| 216 |
+
submit = gr.Button("🚀 Redraw", variant = "primary")
|
| 217 |
|
| 218 |
redrawn_image = gr.Image(label = "Redrawn image")
|
| 219 |
information = gr.Label(label = "Information")
|
| 220 |
original_image = gr.Image(label = "Original image", visible = False)
|
| 221 |
|
| 222 |
submit.click(update_seed, inputs = [
|
| 223 |
+
randomize_seed,
|
| 224 |
+
seed
|
| 225 |
], outputs = [
|
| 226 |
seed
|
| 227 |
], queue = False, show_progress = False).then(toggle_debug, debug_mode, [
|
|
|
|
| 235 |
image_guidance_scale,
|
| 236 |
strength,
|
| 237 |
denoising_steps,
|
| 238 |
+
randomize_seed,
|
| 239 |
seed,
|
| 240 |
debug_mode
|
| 241 |
], outputs = [], queue = False, show_progress = False).success(redraw, inputs = [
|
|
|
|
| 247 |
image_guidance_scale,
|
| 248 |
strength,
|
| 249 |
denoising_steps,
|
| 250 |
+
randomize_seed,
|
| 251 |
seed,
|
| 252 |
debug_mode
|
| 253 |
], outputs = [
|
|
|
|
| 267 |
image_guidance_scale,
|
| 268 |
strength,
|
| 269 |
denoising_steps,
|
| 270 |
+
randomize_seed,
|
| 271 |
seed,
|
| 272 |
debug_mode
|
| 273 |
],
|
|
|
|
| 286 |
1.1,
|
| 287 |
0.6,
|
| 288 |
1000,
|
| 289 |
+
False,
|
| 290 |
42,
|
| 291 |
False
|
| 292 |
],
|