Spaces:
Runtime error
Runtime error
GipAdonimus
commited on
Commit
•
a29fe05
1
Parent(s):
52f2d8f
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,54 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
gr.Interface.load("models/nitrosocke/classic-anim-diffusion").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
gr.Interface.load("models/nitrosocke/classic-anim-diffusion").launch()
|
4 |
+
|
5 |
+
def img_to_img(model_path, prompt, n_images, neg_prompt, img, strength, guidance, steps, width, height, generator, seed):
|
6 |
+
|
7 |
+
print(f"{datetime.datetime.now()} img_to_img, model: {model_path}")
|
8 |
+
|
9 |
+
global last_mode
|
10 |
+
global pipe
|
11 |
+
global current_model_path
|
12 |
+
if model_path != current_model_path or last_mode != "img2img":
|
13 |
+
current_model_path = model_path
|
14 |
+
|
15 |
+
update_state(f"Loading {current_model.name} image-to-image model...")
|
16 |
+
|
17 |
+
if is_colab or current_model == custom_model:
|
18 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
19 |
+
current_model_path,
|
20 |
+
torch_dtype=torch.float16,
|
21 |
+
scheduler=DPMSolverMultistepScheduler.from_pretrained(current_model.path, subfolder="scheduler"),
|
22 |
+
safety_checker=lambda images, clip_input: (images, False)
|
23 |
+
)
|
24 |
+
else:
|
25 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
26 |
+
current_model_path,
|
27 |
+
torch_dtype=torch.float16,
|
28 |
+
scheduler=DPMSolverMultistepScheduler.from_pretrained(current_model.path, subfolder="scheduler")
|
29 |
+
)
|
30 |
+
# pipe = pipe.to("cpu")
|
31 |
+
# pipe = current_model.pipe_i2i
|
32 |
+
|
33 |
+
if torch.cuda.is_available():
|
34 |
+
pipe = pipe.to("cuda")
|
35 |
+
pipe.enable_xformers_memory_efficient_attention()
|
36 |
+
last_mode = "img2img"
|
37 |
+
|
38 |
+
prompt = current_model.prefix + prompt
|
39 |
+
ratio = min(height / img.height, width / img.width)
|
40 |
+
img = img.resize((int(img.width * ratio), int(img.height * ratio)), Image.LANCZOS)
|
41 |
+
result = pipe(
|
42 |
+
prompt,
|
43 |
+
negative_prompt = neg_prompt,
|
44 |
+
num_images_per_prompt=n_images,
|
45 |
+
image = img,
|
46 |
+
num_inference_steps = int(steps),
|
47 |
+
strength = strength,
|
48 |
+
guidance_scale = guidance,
|
49 |
+
# width = width,
|
50 |
+
# height = height,
|
51 |
+
generator = generator,
|
52 |
+
callback=pipe_callback)
|
53 |
+
|
54 |
+
# update_state(f"Done. Seed: {seed}")
|