Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -89,6 +89,49 @@ pipe_scribble.to(device)
|
|
| 89 |
pipe_scribble.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
|
| 90 |
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
def scribble_to_image(text, neg_prompt_box, input_img):
|
| 93 |
"""
|
| 94 |
pass the sd model and do scribble to image
|
|
@@ -148,6 +191,8 @@ def real_img2img_to_anime(text, neg_prompt_box, input_img):
|
|
| 148 |
|
| 149 |
return res_image0, res_image1, res_image2, res_image3
|
| 150 |
|
|
|
|
|
|
|
| 151 |
|
| 152 |
theme = gr.themes.Soft(
|
| 153 |
primary_hue="orange",
|
|
@@ -227,6 +272,41 @@ def mult_thread_lang_class(prompt_box, neg_prompt_box, chinese_check):
|
|
| 227 |
|
| 228 |
|
| 229 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}", title="ShellAI Apps") as iface:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
with gr.Tab("Animefier(安妮漫风)"):
|
| 231 |
gr.Markdown(
|
| 232 |
"""
|
|
@@ -246,7 +326,7 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}", title="ShellAI Ap
|
|
| 246 |
|
| 247 |
image_box = gr.Image(label="Input Image(上传图片)", height=400)
|
| 248 |
gen_btn = gr.Button(value="Generate(生成)")
|
| 249 |
-
|
| 250 |
with gr.Row(equal_height=True):
|
| 251 |
image1 = gr.Image(label="Result 1(结果图 1)")
|
| 252 |
image2 = gr.Image(label="Result 2(结果图 2)")
|
|
|
|
| 89 |
pipe_scribble.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
|
| 90 |
|
| 91 |
|
| 92 |
+
depth_estimator = pipeline('depth-estimation')
|
| 93 |
+
|
| 94 |
+
controlnet_depth = ControlNetModel.from_pretrained(
|
| 95 |
+
"lllyasviel/sd-controlnet-depth", torch_dtype=torch.float16
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
pipe_depth = StableDiffusionControlNetPipeline.from_single_file(
|
| 100 |
+
"https://huggingface.co/shellypeng/anime-god/blob/main/animeGod_v10.safetensors", controlnet=controlnet_depth,
|
| 101 |
+
torch_dtype=torch.float16,
|
| 102 |
+
)
|
| 103 |
+
pipe_depth.load_lora_weights("shellypeng/lora1")
|
| 104 |
+
pipe_depth.fuse_lora(lora_scale=1.5)
|
| 105 |
+
|
| 106 |
+
pipe_depth.load_textual_inversion("shellypeng/textinv1")
|
| 107 |
+
pipe_depth.load_textual_inversion("shellypeng/textinv2")
|
| 108 |
+
pipe_depth.load_textual_inversion("shellypeng/textinv3")
|
| 109 |
+
pipe_depth.load_textual_inversion("shellypeng/textinv4")
|
| 110 |
+
pipe_depth.scheduler = DPMSolverMultistepScheduler.from_config(pipe_depth.scheduler.config, use_karras_sigmas=True)
|
| 111 |
+
def dummy(images, **kwargs):
|
| 112 |
+
return images, False
|
| 113 |
+
pipe_depth.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
|
| 114 |
+
pipe_depth.to(device)
|
| 115 |
+
|
| 116 |
+
def real_to_anime(text, input_img):
|
| 117 |
+
"""
|
| 118 |
+
pass the sd model and do scribble to image
|
| 119 |
+
include Adetailer, detail tweaker lora, prompt backend include: beautiful eyes, beautiful face, beautiful hand, (maybe infer from user's prompt for gesture and facial
|
| 120 |
+
expression to improve hand)
|
| 121 |
+
"""
|
| 122 |
+
input_img = Image.fromarray(input_img)
|
| 123 |
+
input_img = load_image(input_img)
|
| 124 |
+
input_img = depth_estimator(input_img)['depth']
|
| 125 |
+
res_image0 = pipe_depth(prompt, input_img, negative_prompt=hidden_negative, num_inference_steps=40).images[0]
|
| 126 |
+
res_image1 = pipe_depth(prompt, input_img, negative_prompt=hidden_negative, num_inference_steps=40).images[0]
|
| 127 |
+
res_image2 = pipe_depth(prompt, input_img, negative_prompt=hidden_negative, num_inference_steps=40).images[0]
|
| 128 |
+
res_image3 = pipe_depth(prompt, input_img, negative_prompt=hidden_negative, num_inference_steps=40).images[0]
|
| 129 |
+
|
| 130 |
+
return res_image0, res_image1, res_image2, res_image3
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
def scribble_to_image(text, neg_prompt_box, input_img):
|
| 136 |
"""
|
| 137 |
pass the sd model and do scribble to image
|
|
|
|
| 191 |
|
| 192 |
return res_image0, res_image1, res_image2, res_image3
|
| 193 |
|
| 194 |
+
|
| 195 |
+
|
| 196 |
|
| 197 |
theme = gr.themes.Soft(
|
| 198 |
primary_hue="orange",
|
|
|
|
| 272 |
|
| 273 |
|
| 274 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}", title="ShellAI Apps") as iface:
|
| 275 |
+
with gr.Tab("AnimeDepth(安妮深度)"):
|
| 276 |
+
gr.Markdown(
|
| 277 |
+
"""
|
| 278 |
+
# AnimeDepth(安妮深度)
|
| 279 |
+
Turns pictures into one in the anime style with depth-to-image controlnet.
|
| 280 |
+
将图片用深度图的方式转为动漫风图片。
|
| 281 |
+
"""
|
| 282 |
+
)
|
| 283 |
+
with gr.Row(equal_height=True):
|
| 284 |
+
with gr.Column():
|
| 285 |
+
with gr.Row(equal_height=True):
|
| 286 |
+
with gr.Column(scale=4):
|
| 287 |
+
prompt_box = gr.Textbox(label="Prompt(提示词)", placeholder="Enter a prompt\n输入提示词", lines=3)
|
| 288 |
+
neg_prompt_box = gr.Textbox(label="Negative Prompt(负面提示词)", placeholder="Enter a negative prompt(things you don't want to include in the generated image)\n输入负面提示词:输入您不想生成的部分", lines=3)
|
| 289 |
+
with gr.Row(equal_height=True):
|
| 290 |
+
chinese_check = gr.Checkbox(label="Chinese Prompt Mode(中文提示词模式)", info="Click here to enable Chinese Prompting(点此触发中文提示词输入)")
|
| 291 |
+
|
| 292 |
+
image_box = gr.Image(label="Input Image(上传图片)", height=400)
|
| 293 |
+
gen_btn = gr.Button(value="Generate(生成)")
|
| 294 |
+
|
| 295 |
+
with gr.Row(equal_height=True):
|
| 296 |
+
image1 = gr.Image(label="Result 1(结果图 1)")
|
| 297 |
+
image2 = gr.Image(label="Result 2(结果图 2)")
|
| 298 |
+
image3 = gr.Image(label="Result 3(结果图 3)")
|
| 299 |
+
image4 = gr.Image(label="Result 4(结果图 4)")
|
| 300 |
+
example_img2img = [
|
| 301 |
+
["漂亮的女孩,微笑,长发,黑发,粉色外套,白色内衬,优雅,红色背景,红色窗帘", "低画质", "sunmi.jpg"],
|
| 302 |
+
["Beautiful girl, smiling, bun, bun hair, black hair, beautiful eyes, black dress, elegant, red carpet photo","ugly, bad quality", "emma.jpg"]
|
| 303 |
+
]
|
| 304 |
+
|
| 305 |
+
gr.Examples(examples=example_img2img, inputs=[prompt_box, neg_prompt_box, image_box], outputs=[image1, image2, image3, image4], fn=mult_thread_img2img, cache_examples=True)
|
| 306 |
+
|
| 307 |
+
gr.on(triggers=[prompt_box.submit, gen_btn.click],fn=mult_thread_lang_class, inputs=[prompt_box, neg_prompt_box, chinese_check], outputs=[chinese_check], show_progress=False)
|
| 308 |
+
gr.on(triggers=[prompt_box.submit, gen_btn.click],fn=real_to_anime, inputs=[prompt_box, neg_prompt_box, image_box], outputs=[image1, image2, image3, image4])
|
| 309 |
+
|
| 310 |
with gr.Tab("Animefier(安妮漫风)"):
|
| 311 |
gr.Markdown(
|
| 312 |
"""
|
|
|
|
| 326 |
|
| 327 |
image_box = gr.Image(label="Input Image(上传图片)", height=400)
|
| 328 |
gen_btn = gr.Button(value="Generate(生成)")
|
| 329 |
+
|
| 330 |
with gr.Row(equal_height=True):
|
| 331 |
image1 = gr.Image(label="Result 1(结果图 1)")
|
| 332 |
image2 = gr.Image(label="Result 2(结果图 2)")
|