Spaces:
Sleeping
Sleeping
amazonaws-sp
commited on
Commit
•
d9c1ade
1
Parent(s):
87d3aad
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,15 @@
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
5 |
-
import requests
|
6 |
import os
|
7 |
import random
|
8 |
|
9 |
import gradio as gr
|
10 |
import numpy as np
|
|
|
11 |
import spaces
|
12 |
import torch
|
13 |
-
from
|
14 |
-
from io import BytesIO
|
15 |
-
from diffusers import AutoencoderKL, DiffusionPipeline, StableDiffusionImg2ImgPipeline
|
16 |
|
17 |
DESCRIPTION = "# Run any LoRA or SD Model"
|
18 |
if not torch.cuda.is_available():
|
@@ -50,22 +48,16 @@ def generate(
|
|
50 |
num_inference_steps_base: int = 25,
|
51 |
use_vae: bool = False,
|
52 |
use_lora: bool = False,
|
53 |
-
model = '
|
54 |
vaecall = 'madebyollin/sdxl-vae-fp16-fix',
|
55 |
lora = '',
|
56 |
lora_scale: float = 0.7,
|
57 |
-
):
|
58 |
if torch.cuda.is_available():
|
59 |
|
60 |
if not use_vae:
|
61 |
-
pipe =
|
62 |
|
63 |
-
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
64 |
-
|
65 |
-
response = requests.get(url)
|
66 |
-
init_image = Image.open(BytesIO(response.content)).convert("RGB")
|
67 |
-
init_image = init_image.resize((768, 512))
|
68 |
-
|
69 |
if use_vae:
|
70 |
vae = AutoencoderKL.from_pretrained(vaecall, torch_dtype=torch.float16)
|
71 |
pipe = DiffusionPipeline.from_pretrained(model, vae=vae, torch_dtype=torch.float16)
|
@@ -92,9 +84,8 @@ def generate(
|
|
92 |
if not use_negative_prompt_2:
|
93 |
negative_prompt_2 = None # type: ignore
|
94 |
|
95 |
-
|
96 |
prompt=prompt,
|
97 |
-
image=init_image,
|
98 |
negative_prompt=negative_prompt,
|
99 |
prompt_2=prompt_2,
|
100 |
negative_prompt_2=negative_prompt_2,
|
@@ -105,7 +96,7 @@ def generate(
|
|
105 |
generator=generator,
|
106 |
output_type="pil",
|
107 |
).images[0]
|
108 |
-
return
|
109 |
|
110 |
examples = [
|
111 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
@@ -129,6 +120,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css="style.css") as demo:
|
|
129 |
step=0.01,
|
130 |
value=0.7,
|
131 |
)
|
|
|
132 |
with gr.Row():
|
133 |
prompt = gr.Text(
|
134 |
placeholder="Input prompt",
|
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
|
|
5 |
import os
|
6 |
import random
|
7 |
|
8 |
import gradio as gr
|
9 |
import numpy as np
|
10 |
+
import PIL.Image
|
11 |
import spaces
|
12 |
import torch
|
13 |
+
from diffusers import AutoencoderKL, DiffusionPipeline
|
|
|
|
|
14 |
|
15 |
DESCRIPTION = "# Run any LoRA or SD Model"
|
16 |
if not torch.cuda.is_available():
|
|
|
48 |
num_inference_steps_base: int = 25,
|
49 |
use_vae: bool = False,
|
50 |
use_lora: bool = False,
|
51 |
+
model = 'stabilityai/stable-diffusion-xl-base-1.0',
|
52 |
vaecall = 'madebyollin/sdxl-vae-fp16-fix',
|
53 |
lora = '',
|
54 |
lora_scale: float = 0.7,
|
55 |
+
) -> PIL.Image.Image:
|
56 |
if torch.cuda.is_available():
|
57 |
|
58 |
if not use_vae:
|
59 |
+
pipe = DiffusionPipeline.from_pretrained(model, torch_dtype=torch.float16)
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
if use_vae:
|
62 |
vae = AutoencoderKL.from_pretrained(vaecall, torch_dtype=torch.float16)
|
63 |
pipe = DiffusionPipeline.from_pretrained(model, vae=vae, torch_dtype=torch.float16)
|
|
|
84 |
if not use_negative_prompt_2:
|
85 |
negative_prompt_2 = None # type: ignore
|
86 |
|
87 |
+
return pipe(
|
88 |
prompt=prompt,
|
|
|
89 |
negative_prompt=negative_prompt,
|
90 |
prompt_2=prompt_2,
|
91 |
negative_prompt_2=negative_prompt_2,
|
|
|
96 |
generator=generator,
|
97 |
output_type="pil",
|
98 |
).images[0]
|
99 |
+
return image
|
100 |
|
101 |
examples = [
|
102 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
|
|
120 |
step=0.01,
|
121 |
value=0.7,
|
122 |
)
|
123 |
+
upload = gr.Image(label='Image2Image')
|
124 |
with gr.Row():
|
125 |
prompt = gr.Text(
|
126 |
placeholder="Input prompt",
|