Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,16 @@
|
|
1 |
import os
|
2 |
import random
|
3 |
import uuid
|
4 |
-
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
from PIL import Image
|
8 |
import spaces
|
9 |
import torch
|
10 |
-
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
11 |
-
|
12 |
-
#Load the HTML content
|
13 |
-
#html_file_url = "https://prithivmlmods-hamster-static.static.hf.space/index.html"
|
14 |
-
#html_content = f'<iframe src="{html_file_url}" style="width:100%; height:180px; border:none;"></iframe>'
|
15 |
-
#html_file_url = "https://prithivmlmods-static-loading-theme.static.hf.space/index.html"
|
16 |
-
|
17 |
-
#html_file_url = "https://prithivhamster.vercel.app/"
|
18 |
-
#html_content = f'<iframe src="{html_file_url}" style="width:100%; height:400px; border:none"></iframe>'
|
19 |
-
|
20 |
-
DESCRIPTIONx = """## STABLE HAMSTER
|
21 |
-
"""
|
22 |
-
|
23 |
-
css = '''
|
24 |
-
.gradio-container{max-width: 560px !important}
|
25 |
-
h1{text-align:center}
|
26 |
-
footer {
|
27 |
-
visibility: hidden
|
28 |
-
}
|
29 |
-
'''
|
30 |
-
|
31 |
-
examples = [
|
32 |
-
"3d image, cute girl, in the style of Pixar --ar 1:2 --stylize 750, 4K resolution highlights, Sharp focus, octane render, ray tracing, Ultra-High-Definition, 8k, UHD, HDR, (Masterpiece:1.5), (best quality:1.5)",
|
33 |
-
"Cold coffee in a cup bokeh --ar 85:128 --v 6.0 --style raw5, 4K",
|
34 |
-
"Commercial portrait a beautiful multiracial girl in pink jacket, chiseled cheeks, tearful eyes, domina, low neckline, strapless, chocker, in the style of made of liquid metal, deconstructed tailoring, webcam photography, duckcore, bold curves, chinapunk, Jacquemus and moncler collaboration: white translucent fur sunglasses, hyper-realistic, detailed 8k",
|
35 |
-
"A pair of nike Air Jordan snipes | white and red | empty background | commercial shot --s 750"
|
36 |
-
|
37 |
-
]
|
38 |
|
39 |
-
|
40 |
-
#set VAR_NAME=”VALUE”
|
41 |
-
#Fetch an environment variable
|
42 |
-
#echo %VAR_NAME%
|
43 |
|
44 |
MODEL_ID = os.getenv("MODEL_REPO")
|
45 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
|
@@ -47,7 +18,7 @@ USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
|
|
47 |
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
48 |
BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1")) # Allow generating multiple images at once
|
49 |
|
50 |
-
#Load model outside of function
|
51 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
52 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
53 |
MODEL_ID,
|
@@ -66,6 +37,17 @@ if ENABLE_CPU_OFFLOAD:
|
|
66 |
pipe.enable_model_cpu_offload()
|
67 |
|
68 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
def save_image(img):
|
71 |
unique_name = str(uuid.uuid4()) + ".png"
|
@@ -77,157 +59,309 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
77 |
seed = random.randint(0, MAX_SEED)
|
78 |
return seed
|
79 |
|
80 |
-
@spaces.GPU
|
81 |
def generate(
|
82 |
prompt: str,
|
83 |
negative_prompt: str = "",
|
84 |
use_negative_prompt: bool = False,
|
85 |
-
seed: int =
|
86 |
width: int = 1024,
|
87 |
height: int = 1024,
|
88 |
-
guidance_scale: float =
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
randomize_seed: bool = False,
|
91 |
-
|
92 |
-
|
|
|
|
|
93 |
progress=gr.Progress(track_tqdm=True),
|
94 |
):
|
|
|
|
|
95 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
96 |
-
generator = torch.Generator(
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
)
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
label="Number of Images",
|
142 |
-
minimum=1,
|
143 |
-
maximum=4,
|
144 |
-
step=1,
|
145 |
-
value=1,
|
146 |
-
)
|
147 |
-
with gr.Row():
|
148 |
-
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
149 |
-
negative_prompt = gr.Text(
|
150 |
-
label="Negative prompt",
|
151 |
-
max_lines=5,
|
152 |
-
lines=4,
|
153 |
-
placeholder="Enter a negative prompt",
|
154 |
-
value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
|
155 |
-
visible=True,
|
156 |
)
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
)
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
)
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
)
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
)
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
negative_prompt,
|
219 |
-
use_negative_prompt,
|
220 |
-
seed,
|
221 |
-
width,
|
222 |
-
height,
|
223 |
-
guidance_scale,
|
224 |
-
num_inference_steps,
|
225 |
-
randomize_seed,
|
226 |
-
num_images
|
227 |
-
],
|
228 |
-
outputs=[result, seed],
|
229 |
-
api_name="run",
|
230 |
-
)
|
231 |
-
#gr.HTML(html_content)
|
232 |
if __name__ == "__main__":
|
233 |
-
demo.queue(
|
|
|
1 |
import os
|
2 |
import random
|
3 |
import uuid
|
4 |
+
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
from PIL import Image
|
8 |
import spaces
|
9 |
import torch
|
10 |
+
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler, StableDiffusion3Img2ImgPipeline
|
11 |
+
from huggingface_hub import snapshot_download
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
|
|
|
|
|
|
|
14 |
|
15 |
MODEL_ID = os.getenv("MODEL_REPO")
|
16 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
|
|
|
18 |
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
19 |
BATCH_SIZE = int(os.getenv("BATCH_SIZE", "1")) # Allow generating multiple images at once
|
20 |
|
21 |
+
# Load model outside of function
|
22 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
23 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
24 |
MODEL_ID,
|
|
|
37 |
pipe.enable_model_cpu_offload()
|
38 |
|
39 |
MAX_SEED = np.iinfo(np.int32).max
|
40 |
+
CACHE_EXAMPLES = False
|
41 |
+
|
42 |
+
DESCRIPTION = """# Stable Diffusion XL"""
|
43 |
+
if not torch.cuda.is_available():
|
44 |
+
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo may not work on CPU.</p>"
|
45 |
+
|
46 |
+
def load_pipeline(pipeline_type):
|
47 |
+
if pipeline_type == "text2img":
|
48 |
+
return pipe
|
49 |
+
elif pipeline_type == "img2img":
|
50 |
+
return StableDiffusion3Img2ImgPipeline.from_pretrained(MODEL_ID, torch_dtype=torch.float16)
|
51 |
|
52 |
def save_image(img):
|
53 |
unique_name = str(uuid.uuid4()) + ".png"
|
|
|
59 |
seed = random.randint(0, MAX_SEED)
|
60 |
return seed
|
61 |
|
62 |
+
@spaces.GPU
|
63 |
def generate(
|
64 |
prompt: str,
|
65 |
negative_prompt: str = "",
|
66 |
use_negative_prompt: bool = False,
|
67 |
+
seed: int = 0,
|
68 |
width: int = 1024,
|
69 |
height: int = 1024,
|
70 |
+
guidance_scale: float = 7,
|
71 |
+
randomize_seed: bool = False,
|
72 |
+
num_inference_steps=30,
|
73 |
+
NUM_IMAGES_PER_PROMPT=1,
|
74 |
+
use_resolution_binning: bool = True,
|
75 |
+
progress=gr.Progress(track_tqdm=True),
|
76 |
+
):
|
77 |
+
pipe = load_pipeline("text2img")
|
78 |
+
pipe.to(device)
|
79 |
+
seed = int(randomize_seed_fn(seed, randomize_seed))
|
80 |
+
generator = torch.Generator().manual_seed(seed)
|
81 |
+
|
82 |
+
if not use_negative_prompt:
|
83 |
+
negative_prompt = None # type: ignore
|
84 |
+
|
85 |
+
output = pipe(
|
86 |
+
prompt=prompt,
|
87 |
+
negative_prompt=negative_prompt,
|
88 |
+
width=width,
|
89 |
+
height=height,
|
90 |
+
guidance_scale=guidance_scale,
|
91 |
+
num_inference_steps=num_inference_steps,
|
92 |
+
generator=generator,
|
93 |
+
num_images_per_prompt=NUM_IMAGES_PER_PROMPT,
|
94 |
+
output_type="battery",
|
95 |
+
).images
|
96 |
+
|
97 |
+
return output
|
98 |
+
|
99 |
+
@spaces.GPU
|
100 |
+
def img2img_generate(
|
101 |
+
prompt: str,
|
102 |
+
init_image: gr.Image,
|
103 |
+
negative_prompt: str = "",
|
104 |
+
use_negative_prompt: bool = False,
|
105 |
+
seed: int = 0,
|
106 |
+
guidance_scale: float = 7,
|
107 |
randomize_seed: bool = False,
|
108 |
+
num_inference_steps=30,
|
109 |
+
strength: float = 0.8,
|
110 |
+
NUM_IMAGES_PER_PROMPT=1,
|
111 |
+
use_resolution_binning: bool = True,
|
112 |
progress=gr.Progress(track_tqdm=True),
|
113 |
):
|
114 |
+
pipe = load_pipeline("img2img")
|
115 |
+
pipe.to(device)
|
116 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
117 |
+
generator = torch.Generator().manual_seed(seed)
|
118 |
+
|
119 |
+
if not use_negative_prompt:
|
120 |
+
negative_prompt = None # type: ignore
|
121 |
+
|
122 |
+
init_image = init_image.resize((768, 768))
|
123 |
+
|
124 |
+
output = pipe(
|
125 |
+
prompt=prompt,
|
126 |
+
image=init_image,
|
127 |
+
negative_prompt=negative_prompt,
|
128 |
+
guidance_scale=guidance_scale,
|
129 |
+
num_inference_steps=num_inference_steps,
|
130 |
+
generator=generator,
|
131 |
+
strength=strength,
|
132 |
+
num_images_per_prompt=NUM_IMAGES_PER_PROMPT,
|
133 |
+
output_type="battery",
|
134 |
+
).images
|
135 |
+
|
136 |
+
return output
|
137 |
+
|
138 |
+
examples = [
|
139 |
+
"A cardboard with text 'New York' which is large and sits on a theater stage.",
|
140 |
+
"A red sofa on top of a white building.",
|
141 |
+
"A painting of an astronaut riding a pig wearing a tutu holding a pink umbrella.",
|
142 |
+
"Studio photograph closeup of a chameleon over a black background.",
|
143 |
+
"Closeup portrait photo of beautiful goth woman, makeup.",
|
144 |
+
"A living room, bright modern Scandinavian style house, large windows.",
|
145 |
+
"Portrait photograph of an anthropomorphic tortoise seated on a New York City subway train.",
|
146 |
+
"Batman, cute modern Disney style, Pixar 3d portrait, ultra detailed, gorgeous, 3d zbrush, trending on dribbble, 8k render.",
|
147 |
+
"Cinnamon bun on the plate, watercolor painting, detailed, brush strokes, light palette, light, cozy.",
|
148 |
+
"A lion, colorful, low-poly, cyan and orange eyes, poly-hd, 3d, low-poly game art, polygon mesh, jagged, blocky, wireframe edges, centered composition.",
|
149 |
+
"Long exposure photo of Tokyo street, blurred motion, streaks of light, surreal, dreamy, ghosting effect, highly detailed.",
|
150 |
+
"A glamorous digital magazine photoshoot, a fashionable model wearing avant-garde clothing, set in a futuristic cyberpunk roof-top environment, with a neon-lit city background, intricate high fashion details, backlit by vibrant city glow, Vogue fashion photography.",
|
151 |
+
"Masterpiece, best quality, girl, collarbone, wavy hair, looking at viewer, blurry foreground, upper body, necklace, contemporary, plain pants, intricate, print, pattern, ponytail, freckles, red hair, dappled sunlight, smile, happy."
|
152 |
+
]
|
153 |
+
|
154 |
+
css = '''
|
155 |
+
.gradio-container{max-width: 1000px !important}
|
156 |
+
h1{text-align:center}
|
157 |
+
'''
|
158 |
+
with gr.Blocks(css=css, theme="snehilsanyal/scikit-learn") as demo:
|
159 |
+
with gr.Row():
|
160 |
+
with gr.Column():
|
161 |
+
gr.HTML(
|
162 |
+
"""
|
163 |
+
<h1 style='text-align: center'>
|
164 |
+
Stable Diffusion XL
|
165 |
+
</h1>
|
166 |
+
"""
|
167 |
)
|
168 |
+
gr.HTML(
|
169 |
+
"""
|
170 |
+
|
171 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
)
|
173 |
+
|
174 |
+
with gr.Tabs():
|
175 |
+
with gr.TabItem("Text to Image"):
|
176 |
+
with gr.Group():
|
177 |
+
with gr.Row():
|
178 |
+
prompt = gr.Text(
|
179 |
+
label="Prompt",
|
180 |
+
show_label=False,
|
181 |
+
max_lines=1,
|
182 |
+
placeholder="Enter your prompt",
|
183 |
+
container=False,
|
184 |
+
)
|
185 |
+
run_button = gr.Button("Run", scale=0)
|
186 |
+
result = gr.Gallery(label="Result", elem_id="gallery", show_label=False)
|
187 |
+
with gr.Accordion("Advanced options", open=False):
|
188 |
+
with gr.Row():
|
189 |
+
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
190 |
+
negative_prompt = gr.Text(
|
191 |
+
label="Negative prompt",
|
192 |
+
max_lines=1,
|
193 |
+
value="deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
|
194 |
+
visible=True,
|
195 |
+
)
|
196 |
+
seed = gr.Slider(
|
197 |
+
label="Seed",
|
198 |
+
minimum=0,
|
199 |
+
maximum=MAX_SEED,
|
200 |
+
step=1,
|
201 |
+
value=0,
|
202 |
+
)
|
203 |
+
|
204 |
+
steps = gr.Slider(
|
205 |
+
label="Steps",
|
206 |
+
minimum=0,
|
207 |
+
maximum=60,
|
208 |
+
step=1,
|
209 |
+
value=25,
|
210 |
+
)
|
211 |
+
number_image = gr.Slider(
|
212 |
+
label="Number of Images",
|
213 |
+
minimum=1,
|
214 |
+
maximum=4,
|
215 |
+
step=1,
|
216 |
+
value=2,
|
217 |
+
)
|
218 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
219 |
+
with gr.Row(visible=True):
|
220 |
+
width = gr.Slider(
|
221 |
+
label="Width",
|
222 |
+
minimum=256,
|
223 |
+
maximum=MAX_IMAGE_SIZE,
|
224 |
+
step=32,
|
225 |
+
value=1024,
|
226 |
+
)
|
227 |
+
height = gr.Slider(
|
228 |
+
label="Height",
|
229 |
+
minimum=256,
|
230 |
+
maximum=MAX_IMAGE_SIZE,
|
231 |
+
step=32,
|
232 |
+
value=1024,
|
233 |
+
)
|
234 |
+
with gr.Row():
|
235 |
+
guidance_scale = gr.Slider(
|
236 |
+
label="Guidance Scale",
|
237 |
+
minimum=0.1,
|
238 |
+
maximum=10,
|
239 |
+
step=0.1,
|
240 |
+
value=7.0,
|
241 |
+
)
|
242 |
+
|
243 |
+
gr.Examples(
|
244 |
+
examples=examples,
|
245 |
+
inputs=prompt,
|
246 |
+
outputs=[result],
|
247 |
+
fn=generate,
|
248 |
+
cache_examples=CACHE_EXAMPLES,
|
249 |
)
|
250 |
+
|
251 |
+
use_negative_prompt.change(
|
252 |
+
fn=lambda x: gr.update(visible=x),
|
253 |
+
inputs=use_negative_prompt,
|
254 |
+
outputs=negative_prompt,
|
255 |
+
api_name=False,
|
256 |
)
|
257 |
+
|
258 |
+
gr.on(
|
259 |
+
triggers=[
|
260 |
+
prompt.submit,
|
261 |
+
negative_prompt.submit,
|
262 |
+
run_button.click,
|
263 |
+
],
|
264 |
+
fn=generate,
|
265 |
+
inputs=[
|
266 |
+
prompt,
|
267 |
+
negative_prompt,
|
268 |
+
use_negative_prompt,
|
269 |
+
seed,
|
270 |
+
width,
|
271 |
+
height,
|
272 |
+
guidance_scale,
|
273 |
+
randomize_seed,
|
274 |
+
steps,
|
275 |
+
number_image,
|
276 |
+
],
|
277 |
+
outputs=[result],
|
278 |
+
api_name="run",
|
279 |
)
|
280 |
+
with gr.TabItem("Image to Image"):
|
281 |
+
with gr.Group():
|
282 |
+
with gr.Row(equal_height=True):
|
283 |
+
with gr.Column(scale=1):
|
284 |
+
img2img_prompt = gr.Text(
|
285 |
+
label="Prompt",
|
286 |
+
show_label=False,
|
287 |
+
max_lines=1,
|
288 |
+
placeholder="Enter your prompt",
|
289 |
+
container=False,
|
290 |
+
)
|
291 |
+
init_image = gr.Image(label="Input Image", type="pil")
|
292 |
+
with gr.Row():
|
293 |
+
img2img_run_button = gr.Button("Generate", variant="primary")
|
294 |
+
with gr.Column(scale=1):
|
295 |
+
img2img_output = gr.Gallery(label="Result", elem_id="gallery")
|
296 |
+
with gr.Accordion("Advanced options", open=False):
|
297 |
+
with gr.Row():
|
298 |
+
img2img_use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
299 |
+
img2img_negative_prompt = gr.Text(
|
300 |
+
label="Negative prompt",
|
301 |
+
max_lines=1,
|
302 |
+
value="deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
|
303 |
+
visible=True,
|
304 |
+
)
|
305 |
+
img2img_seed = gr.Slider(
|
306 |
+
label="Seed",
|
307 |
+
minimum=0,
|
308 |
+
maximum=MAX_SEED,
|
309 |
+
step=1,
|
310 |
+
value=0,
|
311 |
+
)
|
312 |
+
img2img_steps = gr.Slider(
|
313 |
+
label="Steps",
|
314 |
+
minimum=0,
|
315 |
+
maximum=60,
|
316 |
+
step=1,
|
317 |
+
value=25,
|
318 |
+
)
|
319 |
+
img2img_number_image = gr.Slider(
|
320 |
+
label="Number of Images",
|
321 |
+
minimum=1,
|
322 |
+
maximum=4,
|
323 |
+
step=1,
|
324 |
+
value=2,
|
325 |
+
)
|
326 |
+
img2img_randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
327 |
+
with gr.Row():
|
328 |
+
img2img_guidance_scale = gr.Slider(
|
329 |
+
label="Guidance Scale",
|
330 |
+
minimum=0.1,
|
331 |
+
maximum=10,
|
332 |
+
step=0.1,
|
333 |
+
value=7.0,
|
334 |
+
)
|
335 |
+
strength = gr.Slider(label="Img2Img Strength", minimum=0.0, maximum=1.0, step=0.01, value=0.8)
|
336 |
+
|
337 |
+
img2img_use_negative_prompt.change(
|
338 |
+
fn=lambda x: gr.update(visible=x),
|
339 |
+
inputs=img2img_use_negative_prompt,
|
340 |
+
outputs=img2img_negative_prompt,
|
341 |
+
api_name=False,
|
342 |
)
|
343 |
|
344 |
+
gr.on(
|
345 |
+
triggers=[
|
346 |
+
img2img_prompt.submit,
|
347 |
+
img2img_negative_prompt.submit,
|
348 |
+
img2img_run_button.click,
|
349 |
+
],
|
350 |
+
fn=img2img_generate,
|
351 |
+
inputs=[
|
352 |
+
img2img_prompt,
|
353 |
+
init_image,
|
354 |
+
img2img_negative_prompt,
|
355 |
+
img2img_use_negative_prompt,
|
356 |
+
img2img_seed,
|
357 |
+
img2img_guidance_scale,
|
358 |
+
img2img_randomize_seed,
|
359 |
+
img2img_steps,
|
360 |
+
strength,
|
361 |
+
img2img_number_image,
|
362 |
+
],
|
363 |
+
outputs=[img2img_output],
|
364 |
+
api_name="img2img_run",
|
365 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
if __name__ == "__main__":
|
367 |
+
demo.queue().launch(show_api=False, debug=False)
|