Spaces:
Running
on
Zero
Running
on
Zero
alfredplpl
commited on
Commit
·
624e415
1
Parent(s):
1bbccbf
Update app.py
Browse files
app.py
CHANGED
@@ -33,13 +33,23 @@ def error_str(error, title="Error"):
|
|
33 |
{error}""" if error else ""
|
34 |
|
35 |
|
36 |
-
def inference(prompt, guidance, steps,
|
37 |
|
38 |
generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
|
39 |
|
40 |
if(not disable_auto_prompt_correction):
|
41 |
prompt,neg_prompt=auto_prompt_correction(prompt,neg_prompt,cool_japan_type)
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
try:
|
44 |
if img is not None:
|
45 |
return img_to_img(prompt, neg_prompt, img, strength, guidance, steps, width, height, generator), None
|
@@ -150,12 +160,17 @@ with gr.Blocks(css=css) as demo:
|
|
150 |
cool_japan_type=gr.Radio(["Anime", "Manga", "Game"])
|
151 |
cool_japan_type.show_label=False
|
152 |
cool_japan_type.value="Anime"
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
with gr.Row():
|
155 |
prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="[your prompt]").style(container=False)
|
156 |
generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
|
157 |
|
158 |
-
image_out = gr.Image(height=
|
159 |
error_output = gr.Markdown()
|
160 |
|
161 |
with gr.Column(scale=45):
|
@@ -168,10 +183,6 @@ with gr.Blocks(css=css) as demo:
|
|
168 |
guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=15)
|
169 |
steps = gr.Slider(label="Steps", value=20, minimum=2, maximum=75, step=1)
|
170 |
|
171 |
-
with gr.Row():
|
172 |
-
width = gr.Slider(label="Width", value=512, minimum=64, maximum=1024, step=8)
|
173 |
-
height = gr.Slider(label="Height", value=512, minimum=64, maximum=1024, step=8)
|
174 |
-
|
175 |
seed = gr.Slider(0, 2147483647, label='Seed (0 = random)', value=0, step=1)
|
176 |
|
177 |
with gr.Tab("Image to image"):
|
@@ -179,7 +190,7 @@ with gr.Blocks(css=css) as demo:
|
|
179 |
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
180 |
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
181 |
|
182 |
-
inputs = [prompt, guidance, steps,
|
183 |
|
184 |
outputs = [image_out, error_output]
|
185 |
prompt.submit(inference, inputs=inputs, outputs=outputs)
|
|
|
33 |
{error}""" if error else ""
|
34 |
|
35 |
|
36 |
+
def inference(prompt, guidance, steps, image_size="Square", seed=0, img=None, strength=0.5, neg_prompt="", cool_japan_type="Anime", disable_auto_prompt_correction=False):
|
37 |
|
38 |
generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
|
39 |
|
40 |
if(not disable_auto_prompt_correction):
|
41 |
prompt,neg_prompt=auto_prompt_correction(prompt,neg_prompt,cool_japan_type)
|
42 |
|
43 |
+
if(image_size=="Portrait"):
|
44 |
+
height=768
|
45 |
+
width=576
|
46 |
+
elif(image_size=="Landscape"):
|
47 |
+
height=576
|
48 |
+
width=768
|
49 |
+
else:
|
50 |
+
height=512
|
51 |
+
width=512
|
52 |
+
|
53 |
try:
|
54 |
if img is not None:
|
55 |
return img_to_img(prompt, neg_prompt, img, strength, guidance, steps, width, height, generator), None
|
|
|
160 |
cool_japan_type=gr.Radio(["Anime", "Manga", "Game"])
|
161 |
cool_japan_type.show_label=False
|
162 |
cool_japan_type.value="Anime"
|
163 |
+
|
164 |
+
with gr.Row():
|
165 |
+
image_size=gr.Radio(["Portrait","Landscape","Square"])
|
166 |
+
cool_japan_type.show_label=False
|
167 |
+
cool_japan_type.value="Portrait"
|
168 |
|
169 |
with gr.Row():
|
170 |
prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="[your prompt]").style(container=False)
|
171 |
generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
|
172 |
|
173 |
+
image_out = gr.Image(height=768,width=576)
|
174 |
error_output = gr.Markdown()
|
175 |
|
176 |
with gr.Column(scale=45):
|
|
|
183 |
guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=15)
|
184 |
steps = gr.Slider(label="Steps", value=20, minimum=2, maximum=75, step=1)
|
185 |
|
|
|
|
|
|
|
|
|
186 |
seed = gr.Slider(0, 2147483647, label='Seed (0 = random)', value=0, step=1)
|
187 |
|
188 |
with gr.Tab("Image to image"):
|
|
|
190 |
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
191 |
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
192 |
|
193 |
+
inputs = [prompt, guidance, steps, image_size, seed, image, strength, neg_prompt, cool_japan_type, disable_auto_prompt_correction]
|
194 |
|
195 |
outputs = [image_out, error_output]
|
196 |
prompt.submit(inference, inputs=inputs, outputs=outputs)
|