Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,32 @@
|
|
| 1 |
-
|
| 2 |
-
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
|
| 3 |
import torch
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
-
|
| 8 |
-
controlnet = ControlNetModel.from_pretrained(
|
| 9 |
-
"lllyasviel/control_v11p_sd15_lineart",
|
| 10 |
-
torch_dtype=torch.float16
|
| 11 |
-
)
|
| 12 |
|
| 13 |
-
pipe =
|
| 14 |
-
"
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
torch_dtype=torch.float16
|
| 18 |
-
).to(device)
|
| 19 |
|
| 20 |
-
def colorize(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
result = pipe(
|
| 22 |
-
prompt=
|
| 23 |
-
image=
|
| 24 |
-
|
|
|
|
| 25 |
).images[0]
|
| 26 |
return result
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
demo.launch()
|
| 36 |
|
|
|
|
|
|
| 1 |
+
from diffusers import AutoPipelineForImage2Image
|
|
|
|
| 2 |
import torch
|
| 3 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 6 |
+
"stabilityai/sd-turbo",
|
| 7 |
+
torch_dtype=torch.float32
|
| 8 |
+
).to("cpu")
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def colorize(image):
|
| 11 |
+
prompt = (
|
| 12 |
+
"colorize the sketch while strictly preserving the original line art, "
|
| 13 |
+
"do not add clothing, keep the torso exactly as drawn, leather jacket only"
|
| 14 |
+
)
|
| 15 |
result = pipe(
|
| 16 |
+
prompt=prompt,
|
| 17 |
+
image=image,
|
| 18 |
+
strength=0.6,
|
| 19 |
+
guidance_scale=0.0
|
| 20 |
).images[0]
|
| 21 |
return result
|
| 22 |
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=colorize,
|
| 25 |
+
inputs=gr.Image(type="pil"),
|
| 26 |
+
outputs=gr.Image(type="pil"),
|
| 27 |
+
title="Sketch Colorizer (CPU Optimized)"
|
| 28 |
+
)
|
| 29 |
|
| 30 |
demo.launch()
|
| 31 |
|
| 32 |
+
|