Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
762f660
1
Parent(s):
448bb5b
Update app.py
Browse files
app.py
CHANGED
@@ -79,12 +79,12 @@ def error_str(error, title="Error"):
|
|
79 |
return f"""#### {title}
|
80 |
{error}""" if error else ""
|
81 |
|
82 |
-
def inference(prompt, guidance, steps, image_size="Square", seed=0, img=None, strength=0.5, neg_prompt="", disable_auto_prompt_correction=False, original_model=False):
|
83 |
global pipe,pipe_i2i
|
84 |
|
85 |
generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
|
86 |
|
87 |
-
prompt,neg_prompt=auto_prompt_correction(prompt,neg_prompt,disable_auto_prompt_correction)
|
88 |
|
89 |
if(image_size=="Portrait"):
|
90 |
height=1024
|
@@ -108,18 +108,24 @@ def inference(prompt, guidance, steps, image_size="Square", seed=0, img=None, st
|
|
108 |
return txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator), None
|
109 |
except Exception as e:
|
110 |
return None, error_str(e)
|
111 |
-
def auto_prompt_correction(prompt_ui,neg_prompt_ui,disable_auto_prompt_correction):
|
112 |
# auto prompt correction
|
113 |
prompt=str(prompt_ui)
|
114 |
neg_prompt=str(neg_prompt_ui)
|
115 |
prompt=prompt.lower()
|
116 |
neg_prompt=neg_prompt.lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
if(disable_auto_prompt_correction):
|
118 |
-
prompt=f"
|
119 |
return prompt, neg_prompt
|
120 |
|
121 |
if(prompt=="" and neg_prompt==""):
|
122 |
-
prompt=f"{
|
123 |
neg_prompt=f"{nfixer},(((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
|
124 |
return prompt, neg_prompt
|
125 |
|
@@ -128,21 +134,21 @@ def auto_prompt_correction(prompt_ui,neg_prompt_ui,disable_auto_prompt_correctio
|
|
128 |
human_words=["1girl","girl","maid","maids","female","1woman","woman","girls","2girls","3girls","4girls","5girls","a couple of girls","women","1boy","boy","boys","a couple of boys","2boys","male","1man","1handsome","1bishounen","man","men","guy","guys"]
|
129 |
for word in human_words:
|
130 |
if( word in splited_prompt):
|
131 |
-
prompt=f"
|
132 |
neg_prompt=f"{nfixer},(((deformed))), blurry, ((((bad anatomy)))), {neg_prompt}, bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
|
133 |
return prompt, neg_prompt
|
134 |
|
135 |
animal_words=["cat","dog","bird"]
|
136 |
for word in animal_words:
|
137 |
if( word in splited_prompt):
|
138 |
-
prompt=f"
|
139 |
neg_prompt=f"{nfixer}, girl, (((deformed))), blurry, ((((bad anatomy)))), {neg_prompt}, bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
|
140 |
return prompt, neg_prompt
|
141 |
|
142 |
background_words=["mount fuji","mt. fuji","building", "buildings", "tokyo", "kyoto", "nara", "shibuya", "shinjuku"]
|
143 |
for word in background_words:
|
144 |
if( word in splited_prompt):
|
145 |
-
prompt=f"
|
146 |
neg_prompt=f"girl, (((deformed))), {neg_prompt}, girl, boy, photo, people, low quality, ui, error, lowres, jpeg artifacts, 2d, 3d, cg, text"
|
147 |
return prompt, neg_prompt
|
148 |
|
@@ -208,6 +214,9 @@ with gr.Blocks(css=css) as demo:
|
|
208 |
with gr.Column(scale=55):
|
209 |
with gr.Group():
|
210 |
with gr.Row():
|
|
|
|
|
|
|
211 |
prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="[your prompt]").style(container=False)
|
212 |
generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
|
213 |
|
@@ -236,7 +245,7 @@ with gr.Blocks(css=css) as demo:
|
|
236 |
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
237 |
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
238 |
|
239 |
-
inputs = [prompt, guidance, steps, image_size, seed, image, strength, neg_prompt, disable_auto_prompt_correction]#, original_model]
|
240 |
|
241 |
outputs = [image_out, error_output]
|
242 |
prompt.submit(inference, inputs=inputs, outputs=outputs)
|
|
|
79 |
return f"""#### {title}
|
80 |
{error}""" if error else ""
|
81 |
|
82 |
+
def inference(prompt, guidance, steps, image_size="Square", seed=0, img=None, strength=0.5, neg_prompt="", disable_auto_prompt_correction=False, image_style="Realistic", original_model=False):
|
83 |
global pipe,pipe_i2i
|
84 |
|
85 |
generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
|
86 |
|
87 |
+
prompt,neg_prompt=auto_prompt_correction(prompt,neg_prompt,disable_auto_prompt_correction,image_style)
|
88 |
|
89 |
if(image_size=="Portrait"):
|
90 |
height=1024
|
|
|
108 |
return txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator), None
|
109 |
except Exception as e:
|
110 |
return None, error_str(e)
|
111 |
+
def auto_prompt_correction(prompt_ui,neg_prompt_ui,disable_auto_prompt_correction,image_style):
|
112 |
# auto prompt correction
|
113 |
prompt=str(prompt_ui)
|
114 |
neg_prompt=str(neg_prompt_ui)
|
115 |
prompt=prompt.lower()
|
116 |
neg_prompt=neg_prompt.lower()
|
117 |
+
|
118 |
+
if(image_style=="Animetic"):
|
119 |
+
style="anime"
|
120 |
+
else:
|
121 |
+
style=f"anime,{embellish2}"
|
122 |
+
|
123 |
if(disable_auto_prompt_correction):
|
124 |
+
prompt=f"{style}, {prompt}"
|
125 |
return prompt, neg_prompt
|
126 |
|
127 |
if(prompt=="" and neg_prompt==""):
|
128 |
+
prompt=f"{style}, masterpiece, portrait, a girl with flowers, good pupil, 4k, detailed"
|
129 |
neg_prompt=f"{nfixer},(((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
|
130 |
return prompt, neg_prompt
|
131 |
|
|
|
134 |
human_words=["1girl","girl","maid","maids","female","1woman","woman","girls","2girls","3girls","4girls","5girls","a couple of girls","women","1boy","boy","boys","a couple of boys","2boys","male","1man","1handsome","1bishounen","man","men","guy","guys"]
|
135 |
for word in human_words:
|
136 |
if( word in splited_prompt):
|
137 |
+
prompt=f"{style}, masterpiece, {prompt}, good pupil, 4k, detailed"
|
138 |
neg_prompt=f"{nfixer},(((deformed))), blurry, ((((bad anatomy)))), {neg_prompt}, bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
|
139 |
return prompt, neg_prompt
|
140 |
|
141 |
animal_words=["cat","dog","bird"]
|
142 |
for word in animal_words:
|
143 |
if( word in splited_prompt):
|
144 |
+
prompt=f"{style}, a {prompt}, 4k, detailed"
|
145 |
neg_prompt=f"{nfixer}, girl, (((deformed))), blurry, ((((bad anatomy)))), {neg_prompt}, bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
|
146 |
return prompt, neg_prompt
|
147 |
|
148 |
background_words=["mount fuji","mt. fuji","building", "buildings", "tokyo", "kyoto", "nara", "shibuya", "shinjuku"]
|
149 |
for word in background_words:
|
150 |
if( word in splited_prompt):
|
151 |
+
prompt=f"{style}, shinkai makoto, {word}, 4k, 8k, highly detailed"
|
152 |
neg_prompt=f"girl, (((deformed))), {neg_prompt}, girl, boy, photo, people, low quality, ui, error, lowres, jpeg artifacts, 2d, 3d, cg, text"
|
153 |
return prompt, neg_prompt
|
154 |
|
|
|
214 |
with gr.Column(scale=55):
|
215 |
with gr.Group():
|
216 |
with gr.Row():
|
217 |
+
image_style=gr.Radio(["Realistic","Animetic"])
|
218 |
+
image_style.show_label=False
|
219 |
+
image_style.value="Realistic"
|
220 |
prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="[your prompt]").style(container=False)
|
221 |
generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
|
222 |
|
|
|
245 |
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
246 |
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
247 |
|
248 |
+
inputs = [prompt, guidance, steps, image_size, seed, image, strength, neg_prompt, disable_auto_prompt_correction,image_style]#, original_model]
|
249 |
|
250 |
outputs = [image_out, error_output]
|
251 |
prompt.submit(inference, inputs=inputs, outputs=outputs)
|