Spaces:
Runtime error
Runtime error
Commit
·
e6e7ba3
1
Parent(s):
24cead7
Update app.py
Browse files
app.py
CHANGED
@@ -7,18 +7,17 @@ Original file is located at
|
|
7 |
https://colab.research.google.com/drive/1RxVCwOkq3Q5qlEkQxhFGeUxICBujjEjR
|
8 |
"""
|
9 |
|
|
|
10 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
11 |
|
12 |
tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-zh-en")
|
13 |
|
14 |
model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-zh-en")
|
15 |
|
16 |
-
# from retrying import retry
|
17 |
-
from transformers import CLIPTextModel, CLIPTokenizer, BertTokenizer, BertForSequenceClassification, ChineseCLIPProcessor, ChineseCLIPModel, AutoModel
|
18 |
import gradio as gr
|
19 |
import numpy as np
|
20 |
from PIL import Image
|
21 |
-
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel,
|
22 |
|
23 |
import torch
|
24 |
from controlnet_aux import HEDdetector
|
@@ -28,6 +27,7 @@ import concurrent.futures
|
|
28 |
from threading import Thread
|
29 |
from compel import Compel
|
30 |
|
|
|
31 |
from transformers import pipeline
|
32 |
|
33 |
|
@@ -38,15 +38,11 @@ pipe = pipeline("text-classification", model=model_ckpt)
|
|
38 |
|
39 |
device="cuda" if torch.cuda.is_available() else "cpu"
|
40 |
|
41 |
-
hidden_booster_text = "beautiful face, small boobs, a cup"
|
42 |
hidden_negative = "big boobs, huge boobs, sexy, dirty, d cup, e cup, g cup, slutty, badhandv4, ng_deepnegative_v1_75t, worst quality, low quality, extra digits, text, signature, bad anatomy, mutated hand, error, missing finger, cropped, worse quality, bad quality, lowres, floating limbs, bad hands, anatomical nonsense"
|
43 |
-
hidden_cn_booster_text = "漂亮的脸,小胸,贫乳,a罩杯"
|
44 |
hidden_cn_negative = "大胸, ,, !, 。, ;,巨乳,性感,脏,d罩杯,e罩杯,g罩杯,骚,骚气,badhandv4, ng_deepnegative_v1_75t"
|
45 |
|
46 |
-
# text_tokenizer = CLIPTokenizer.from_pretrained("IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-EN-v0.1")
|
47 |
-
# text_encoder = CLIPTextModel.from_pretrained("IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-EN-v0.1").eval()
|
48 |
-
# text_encoder = ChineseCLIPModel.from_pretrained("OFA-Sys/chinese-clip-vit-base-patch16").eval()
|
49 |
-
|
50 |
def translate(prompt):
|
51 |
trans_text = prompt
|
52 |
translated = model.generate(**tokenizer(trans_text, return_tensors="pt", padding=True))
|
@@ -54,16 +50,13 @@ def translate(prompt):
|
|
54 |
tgt_text = ''.join(tgt_text)[:-1]
|
55 |
return tgt_text
|
56 |
|
57 |
-
from PIL import Image
|
58 |
-
|
59 |
hed = HEDdetector.from_pretrained('lllyasviel/ControlNet')
|
60 |
|
61 |
controlnet_scribble = ControlNetModel.from_pretrained(
|
62 |
-
"lllyasviel/sd-controlnet-scribble", torch_dtype=torch.float16
|
63 |
-
)
|
64 |
|
65 |
pipe_scribble = StableDiffusionControlNetPipeline.from_single_file(
|
66 |
-
"https://huggingface.co/shellypeng/anime-god/blob/main/animeGod_v10.safetensors", controlnet=controlnet_scribble,
|
67 |
torch_dtype=torch.float16,
|
68 |
)
|
69 |
|
@@ -78,8 +71,8 @@ pipe_scribble = StableDiffusionControlNetPipeline.from_single_file(
|
|
78 |
|
79 |
# pipe_scribble.load_lora_weights("shellypeng/detail-tweaker")
|
80 |
# pipe_scribble.fuse_lora(lora_scale=0.1)
|
81 |
-
|
82 |
-
|
83 |
# pipe_scribble.load_lora_weights("shellypeng/beautiful-eyes")
|
84 |
# pipe_scribble.fuse_lora(lora_scale=0.1)
|
85 |
|
@@ -94,9 +87,7 @@ pipe_scribble.safety_checker = None
|
|
94 |
pipe_scribble.requires_safety_checker = False
|
95 |
pipe_scribble.to(device)
|
96 |
|
97 |
-
text
|
98 |
-
|
99 |
-
def scribble_to_image(text, input_img, chinese_check):
|
100 |
"""
|
101 |
pass the sd model and do scribble to image
|
102 |
include Adetailer, detail tweaker lora, prompt backend include: beautiful eyes, beautiful face, beautiful hand, (maybe infer from user's prompt for gesture and facial
|
@@ -111,54 +102,24 @@ def scribble_to_image(text, input_img, chinese_check):
|
|
111 |
input_img = hed(input_img, scribble=True)
|
112 |
input_img = load_image(input_img)
|
113 |
# global prompt
|
114 |
-
compel_proc = Compel(tokenizer=pipe_scribble.tokenizer, text_encoder=pipe_scribble.text_encoder)
|
115 |
lang_check_label = pipe(text, top_k=1, truncation=True)[0]['label']
|
116 |
lang_check_score = pipe(text, top_k=1, truncation=True)[0]['score']
|
117 |
if lang_check_label == 'zh' and lang_check_score >= 0.85:
|
118 |
text = translate(text)
|
119 |
-
|
120 |
prompt = text + hidden_booster_text
|
121 |
prompt_embeds = compel_proc(prompt)
|
|
|
|
|
122 |
|
123 |
-
res_image0 = pipe_scribble(image=input_img, prompt_embeds=prompt_embeds,
|
124 |
-
res_image1 = pipe_scribble(image=input_img, prompt_embeds=prompt_embeds,
|
125 |
-
res_image2 = pipe_scribble(image=input_img, prompt_embeds=prompt_embeds,
|
126 |
-
res_image3 = pipe_scribble(image=input_img, prompt_embeds=prompt_embeds,
|
127 |
|
128 |
return res_image0, res_image1, res_image2, res_image3
|
129 |
|
130 |
-
|
131 |
-
from PIL import Image
|
132 |
-
|
133 |
-
from transformers import pipeline
|
134 |
-
from diffusers import StableDiffusionDepth2ImgPipeline, StableDiffusionPipeline, StableDiffusionControlNetPipeline, StableDiffusionUpscalePipeline, StableDiffusionImg2ImgPipeline, AutoPipelineForImage2Image
|
135 |
-
|
136 |
-
# Commented out IPython magic to ensure Python compatibility.
|
137 |
-
# %cd /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui
|
138 |
-
|
139 |
-
pipe_img2img = StableDiffusionImg2ImgPipeline.from_single_file("https://huggingface.co/shellypeng/anime-god/blob/main/animeGod_v10.safetensors",
|
140 |
-
torch_dtype=torch.float16)
|
141 |
-
|
142 |
-
# pipe_img2img.load_lora_weights("shellypeng/detail-tweaker")
|
143 |
-
# pipe_img2img.fuse_lora(lora_scale=0.1)
|
144 |
-
# pipe_img2img.load_lora_weights("shellypeng/lora-eyes")
|
145 |
-
# pipe_img2img.fuse_lora(lora_scale=0.1)
|
146 |
-
# pipe_img2img.load_lora_weights("shellypeng/beautiful-eyes")
|
147 |
-
# pipe_img2img.fuse_lora(lora_scale=0.1)
|
148 |
-
|
149 |
-
pipe_img2img.load_textual_inversion("shellypeng/bad-prompt")
|
150 |
-
pipe_img2img.load_textual_inversion("shellypeng/badhandv4")
|
151 |
-
# pipe.load_textual_inversion("shellypeng/easynegative")
|
152 |
-
pipe_img2img.load_textual_inversion("shellypeng/deepnegative")
|
153 |
-
pipe_img2img.load_textual_inversion("shellypeng/verybadimagenegative")
|
154 |
-
pipe_img2img.scheduler = DPMSolverMultistepScheduler.from_config(pipe_img2img.scheduler.config, use_karras_sigmas=True)
|
155 |
-
# pipe.enable_model_cpu_offload()
|
156 |
-
pipe_img2img.safety_checker = None
|
157 |
-
pipe_img2img.requires_safety_checker = False
|
158 |
-
pipe_img2img.to(device)
|
159 |
-
|
160 |
-
|
161 |
-
def real_img2img_to_anime(text, input_img, chinese_check):
|
162 |
"""
|
163 |
pass the sd model and do scribble to image
|
164 |
include Adetailer, detail tweaker lora, prompt backend include: beautiful eyes, beautiful face, beautiful hand, (maybe infer from user's prompt for gesture and facial
|
@@ -166,19 +127,22 @@ def real_img2img_to_anime(text, input_img, chinese_check):
|
|
166 |
"""
|
167 |
input_img = Image.fromarray(input_img)
|
168 |
input_img = load_image(input_img)
|
169 |
-
compel_proc = Compel(tokenizer=pipe_scribble.tokenizer, text_encoder=pipe_scribble.text_encoder)
|
170 |
lang_check_label = pipe(text, top_k=1, truncation=True)[0]['label']
|
171 |
lang_check_score = pipe(text, top_k=1, truncation=True)[0]['score']
|
172 |
if lang_check_label == 'zh' and lang_check_score >= 0.85:
|
173 |
text = translate(text)
|
174 |
-
print("prompt text:", text)
|
175 |
-
prompt = text + hidden_booster_text
|
176 |
|
|
|
|
|
177 |
prompt_embeds = compel_proc(prompt)
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
182 |
|
183 |
return res_image0, res_image1, res_image2, res_image3
|
184 |
|
@@ -190,24 +154,151 @@ theme = gr.themes.Soft(
|
|
190 |
block_background_fill='*primary_50'
|
191 |
)
|
192 |
|
193 |
-
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
"Amor, ch'a nullo amato amar perdona."
|
198 |
-
]
|
199 |
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}", title="ShellAI Apps") as iface:
|
205 |
with gr.Tab("Animefier"):
|
206 |
with gr.Row(equal_height=True):
|
207 |
with gr.Column():
|
208 |
with gr.Row(equal_height=True):
|
209 |
-
|
210 |
-
|
|
|
|
|
|
|
211 |
|
212 |
image_box = gr.Image(label="Input Image", height=350)
|
213 |
gen_btn = gr.Button(value="Generate")
|
@@ -217,41 +308,37 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}", title="ShellAI Ap
|
|
217 |
global image2
|
218 |
global image3
|
219 |
global image4
|
220 |
-
image1 = gr.Image()
|
221 |
-
image2 = gr.Image()
|
222 |
-
image3 = gr.Image()
|
223 |
-
image4 = gr.Image()
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
image1, image2, image3, image4 = future.result()
|
229 |
-
return image1, image2, image3, image4
|
230 |
-
gen_btn.click(mult_thread, [prompt_box, image_box, chinese_check], [image1, image2, image3, image4])
|
231 |
|
232 |
with gr.Tab("AniSketch"):
|
233 |
with gr.Row(equal_height=True):
|
234 |
with gr.Column():
|
235 |
with gr.Row(equal_height=True):
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
238 |
|
239 |
image_box = gr.Image(label="Input Image", height=350)
|
240 |
gen_btn = gr.Button(value="Generate")
|
241 |
with gr.Row(equal_height=True):
|
|
|
|
|
|
|
|
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
image3 = gr.Image()
|
246 |
-
image4 = gr.Image()
|
247 |
-
|
248 |
-
def mult_thread(prompt_box, image_box, chinese_check):
|
249 |
-
with concurrent.futures.ThreadPoolExecutor(max_workers=12000) as executor:
|
250 |
-
future = executor.submit(scribble_to_image, prompt_box, image_box, chinese_check)
|
251 |
-
image1, image2, image3, image4 = future.result()
|
252 |
-
|
253 |
-
return image1, image2, image3, image4
|
254 |
|
255 |
-
gen_btn.click(mult_thread, [prompt_box, image_box, chinese_check], [image1, image2, image3, image4])
|
256 |
|
|
|
|
|
257 |
iface.launch(debug=True, share=True, auth=["shenrym", "shjdqw%23-sw2&"])
|
|
|
7 |
https://colab.research.google.com/drive/1RxVCwOkq3Q5qlEkQxhFGeUxICBujjEjR
|
8 |
"""
|
9 |
|
10 |
+
|
11 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
12 |
|
13 |
tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-zh-en")
|
14 |
|
15 |
model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-zh-en")
|
16 |
|
|
|
|
|
17 |
import gradio as gr
|
18 |
import numpy as np
|
19 |
from PIL import Image
|
20 |
+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, DPMSolverMultistepScheduler, StableDiffusionImg2ImgPipeline
|
21 |
|
22 |
import torch
|
23 |
from controlnet_aux import HEDdetector
|
|
|
27 |
from threading import Thread
|
28 |
from compel import Compel
|
29 |
|
30 |
+
|
31 |
from transformers import pipeline
|
32 |
|
33 |
|
|
|
38 |
|
39 |
device="cuda" if torch.cuda.is_available() else "cpu"
|
40 |
|
41 |
+
hidden_booster_text = ", loraeyes, beautiful face, small boobs, a cup"
|
42 |
hidden_negative = "big boobs, huge boobs, sexy, dirty, d cup, e cup, g cup, slutty, badhandv4, ng_deepnegative_v1_75t, worst quality, low quality, extra digits, text, signature, bad anatomy, mutated hand, error, missing finger, cropped, worse quality, bad quality, lowres, floating limbs, bad hands, anatomical nonsense"
|
43 |
+
hidden_cn_booster_text = ",loraeyes漂亮的脸,小胸,贫乳,a罩杯"
|
44 |
hidden_cn_negative = "大胸, ,, !, 。, ;,巨乳,性感,脏,d罩杯,e罩杯,g罩杯,骚,骚气,badhandv4, ng_deepnegative_v1_75t"
|
45 |
|
|
|
|
|
|
|
|
|
46 |
def translate(prompt):
|
47 |
trans_text = prompt
|
48 |
translated = model.generate(**tokenizer(trans_text, return_tensors="pt", padding=True))
|
|
|
50 |
tgt_text = ''.join(tgt_text)[:-1]
|
51 |
return tgt_text
|
52 |
|
|
|
|
|
53 |
hed = HEDdetector.from_pretrained('lllyasviel/ControlNet')
|
54 |
|
55 |
controlnet_scribble = ControlNetModel.from_pretrained(
|
56 |
+
"lllyasviel/sd-controlnet-scribble", torch_dtype=torch.float16, safety_checker=None, requires_safety_checker=False, )
|
|
|
57 |
|
58 |
pipe_scribble = StableDiffusionControlNetPipeline.from_single_file(
|
59 |
+
"https://huggingface.co/shellypeng/anime-god/blob/main/animeGod_v10.safetensors", controlnet=controlnet_scribble, safety_checker=None, requires_safety_checker=False,
|
60 |
torch_dtype=torch.float16,
|
61 |
)
|
62 |
|
|
|
71 |
|
72 |
# pipe_scribble.load_lora_weights("shellypeng/detail-tweaker")
|
73 |
# pipe_scribble.fuse_lora(lora_scale=0.1)
|
74 |
+
pipe_scribble.load_lora_weights("shellypeng/lora-eyes")
|
75 |
+
pipe_scribble.fuse_lora(lora_scale=0.1)
|
76 |
# pipe_scribble.load_lora_weights("shellypeng/beautiful-eyes")
|
77 |
# pipe_scribble.fuse_lora(lora_scale=0.1)
|
78 |
|
|
|
87 |
pipe_scribble.requires_safety_checker = False
|
88 |
pipe_scribble.to(device)
|
89 |
|
90 |
+
def scribble_to_image(text, neg_prompt_box, input_img):
|
|
|
|
|
91 |
"""
|
92 |
pass the sd model and do scribble to image
|
93 |
include Adetailer, detail tweaker lora, prompt backend include: beautiful eyes, beautiful face, beautiful hand, (maybe infer from user's prompt for gesture and facial
|
|
|
102 |
input_img = hed(input_img, scribble=True)
|
103 |
input_img = load_image(input_img)
|
104 |
# global prompt
|
|
|
105 |
lang_check_label = pipe(text, top_k=1, truncation=True)[0]['label']
|
106 |
lang_check_score = pipe(text, top_k=1, truncation=True)[0]['score']
|
107 |
if lang_check_label == 'zh' and lang_check_score >= 0.85:
|
108 |
text = translate(text)
|
109 |
+
compel_proc = Compel(tokenizer=pipe_scribble.tokenizer, text_encoder=pipe_scribble.text_encoder)
|
110 |
prompt = text + hidden_booster_text
|
111 |
prompt_embeds = compel_proc(prompt)
|
112 |
+
negative_prompt = neg_prompt_box + hidden_negative
|
113 |
+
negative_prompt_embeds = compel_proc(negative_prompt)
|
114 |
|
115 |
+
res_image0 = pipe_scribble(image=input_img, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, num_inference_steps=40).images[0]
|
116 |
+
res_image1 = pipe_scribble(image=input_img, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, num_inference_steps=40).images[0]
|
117 |
+
res_image2 = pipe_scribble(image=input_img, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, num_inference_steps=40).images[0]
|
118 |
+
res_image3 = pipe_scribble(image=input_img, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, num_inference_steps=40).images[0]
|
119 |
|
120 |
return res_image0, res_image1, res_image2, res_image3
|
121 |
|
122 |
+
def real_img2img_to_anime(text, neg_prompt_box, input_img):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
"""
|
124 |
pass the sd model and do scribble to image
|
125 |
include Adetailer, detail tweaker lora, prompt backend include: beautiful eyes, beautiful face, beautiful hand, (maybe infer from user's prompt for gesture and facial
|
|
|
127 |
"""
|
128 |
input_img = Image.fromarray(input_img)
|
129 |
input_img = load_image(input_img)
|
|
|
130 |
lang_check_label = pipe(text, top_k=1, truncation=True)[0]['label']
|
131 |
lang_check_score = pipe(text, top_k=1, truncation=True)[0]['score']
|
132 |
if lang_check_label == 'zh' and lang_check_score >= 0.85:
|
133 |
text = translate(text)
|
|
|
|
|
134 |
|
135 |
+
compel_proc = Compel(tokenizer=pipe_scribble.tokenizer, text_encoder=pipe_scribble.text_encoder)
|
136 |
+
prompt = text + hidden_booster_text
|
137 |
prompt_embeds = compel_proc(prompt)
|
138 |
+
|
139 |
+
negative_prompt = neg_prompt_box + hidden_negative
|
140 |
+
negative_prompt_embeds = compel_proc(negative_prompt)
|
141 |
+
# input_img = depth_estimator(input_img)['depth']
|
142 |
+
res_image0 = pipe_img2img(image=input_img, strength=0.6, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, num_inference_steps=40).images[0]
|
143 |
+
res_image1 = pipe_img2img(image=input_img, strength=0.6, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, num_inference_steps=40).images[0]
|
144 |
+
res_image2 = pipe_img2img(image=input_img, strength=0.6, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, num_inference_steps=40).images[0]
|
145 |
+
res_image3 = pipe_img2img(image=input_img, strength=0.6, prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, num_inference_steps=40).images[0]
|
146 |
|
147 |
return res_image0, res_image1, res_image2, res_image3
|
148 |
|
|
|
154 |
block_background_fill='*primary_50'
|
155 |
)
|
156 |
|
157 |
+
# %cd /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui
|
158 |
|
159 |
+
pipe_img2img = StableDiffusionImg2ImgPipeline.from_single_file("https://huggingface.co/shellypeng/anime-god/blob/main/animeGod_v10.safetensors",
|
160 |
+
torch_dtype=torch.float16, safety_checker=None, requires_safety_checker=False)
|
|
|
|
|
161 |
|
162 |
+
# pipe_img2img.load_lora_weights("shellypeng/detail-tweaker")
|
163 |
+
# pipe_img2img.fuse_lora(lora_scale=0.1)
|
164 |
+
pipe_img2img.load_lora_weights("shellypeng/lora-eyes")
|
165 |
+
pipe_img2img.fuse_lora(lora_scale=0.1)
|
166 |
+
# pipe_img2img.load_lora_weights("shellypeng/beautiful-eyes")
|
167 |
+
# pipe_img2img.fuse_lora(lora_scale=0.1)
|
168 |
+
|
169 |
+
pipe_img2img.load_textual_inversion("shellypeng/bad-prompt")
|
170 |
+
pipe_img2img.load_textual_inversion("shellypeng/badhandv4")
|
171 |
+
# pipe.load_textual_inversion("shellypeng/easynegative")
|
172 |
+
pipe_img2img.load_textual_inversion("shellypeng/deepnegative")
|
173 |
+
pipe_img2img.load_textual_inversion("shellypeng/verybadimagenegative")
|
174 |
+
pipe_img2img.scheduler = DPMSolverMultistepScheduler.from_config(pipe_img2img.scheduler.config, use_karras_sigmas=True)
|
175 |
+
# pipe.enable_model_cpu_offload()
|
176 |
+
pipe_img2img.safety_checker = None
|
177 |
+
pipe_img2img.requires_safety_checker = False
|
178 |
+
pipe_img2img.to(device)
|
179 |
+
|
180 |
+
# pipe_img2img.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
|
181 |
+
|
182 |
+
# depth_estimator = pipeline('depth-estimation')
|
183 |
+
|
184 |
+
# controlnet_depth = ControlNetModel.from_pretrained(
|
185 |
+
# "lllyasviel/sd-controlnet-depth", torch_dtype=torch.float16
|
186 |
+
# )
|
187 |
+
|
188 |
+
|
189 |
+
# # models that worked well: anime god, pastel dream,
|
190 |
+
# # https://huggingface.co/shellypeng/featureless/tree/main
|
191 |
+
# pipe_depth = StableDiffusionControlNetPipeline.from_single_file(
|
192 |
+
# "https://huggingface.co/shellypeng/anime-god/blob/main/animeGod_v10.safetensors", controlnet=controlnet_depth,
|
193 |
+
# torch_dtype=torch.float16,
|
194 |
+
# )
|
195 |
+
# # pipe = StableDiffusionControlNetPipeline.from_pretrained("furusu/SSD-1B-anime",
|
196 |
+
# # torch_dtype=torch.float16
|
197 |
+
# # )
|
198 |
+
|
199 |
+
# pipe_depth.load_lora_weights("shellypeng/detail-tweaker")
|
200 |
+
# pipe_depth.fuse_lora(lora_scale=0.1)
|
201 |
+
# # pipe.load_lora_weights("shellypeng/stylized-3d")
|
202 |
+
# # pipe.load_lora_weights("shellypeng/midjourney-anime")
|
203 |
+
|
204 |
+
# # pipe.load_lora_weights("shellypeng/animetarot")
|
205 |
+
# # pipe.load_lora_weights("shellypeng/anime-stickers-v3")
|
206 |
+
# # pipe.load_lora_weights("shellypeng/anime-magazine")
|
207 |
+
|
208 |
+
|
209 |
+
|
210 |
+
# pipe_depth.load_textual_inversion("shellypeng/bad-prompt")
|
211 |
+
# pipe_depth.load_textual_inversion("shellypeng/badhandv4")
|
212 |
+
# # pipe.load_textual_inversion("shellypeng/easynegative")
|
213 |
+
# pipe_depth.load_textual_inversion("shellypeng/deepnegative")
|
214 |
+
# pipe_depth.load_textual_inversion("shellypeng/verybadimagenegative")
|
215 |
+
# pipe_depth.scheduler = DPMSolverMultistepScheduler.from_config(pipe_depth.scheduler.config, use_karras_sigmas=True)
|
216 |
+
# # pipe.enable_model_cpu_offload()
|
217 |
+
# def dummy(images, **kwargs):
|
218 |
+
# return images, False
|
219 |
+
# pipe_depth.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
|
220 |
+
# pipe_depth.to(device)
|
221 |
+
# # pipe.load_lora_weights("shellypeng/detail-tweaker", weight_name="add_detail.safetensors")
|
222 |
+
|
223 |
+
# # load textual inversion negative embeddings!!!: pipe.load_textual_inversion("sd-concepts-library/cat-toy")
|
224 |
+
|
225 |
+
# def real_to_anime(text, input_img):
|
226 |
+
# """
|
227 |
+
# pass the sd model and do scribble to image
|
228 |
+
# include Adetailer, detail tweaker lora, prompt backend include: beautiful eyes, beautiful face, beautiful hand, (maybe infer from user's prompt for gesture and facial
|
229 |
+
# expression to improve hand)
|
230 |
+
# """
|
231 |
+
# input_img = Image.fromarray(input_img)
|
232 |
+
# input_img = load_image(input_img)
|
233 |
+
# input_img = depth_estimator(input_img)['depth']
|
234 |
+
# res_image0 = pipe_depth(prompt, input_img, negative_prompt=hidden_negative, num_inference_steps=40).images[0]
|
235 |
+
# res_image1 = pipe_depth(prompt, input_img, negative_prompt=hidden_negative, num_inference_steps=40).images[0]
|
236 |
+
# res_image2 = pipe_depth(prompt, input_img, negative_prompt=hidden_negative, num_inference_steps=40).images[0]
|
237 |
+
# res_image3 = pipe_depth(prompt, input_img, negative_prompt=hidden_negative, num_inference_steps=40).images[0]
|
238 |
+
|
239 |
+
# return res_image0, res_image1, res_image2, res_image3
|
240 |
+
|
241 |
+
|
242 |
+
# theme = gr.themes.Soft(
|
243 |
+
# primary_hue="orange",
|
244 |
+
# secondary_hue="orange",
|
245 |
+
# ).set(
|
246 |
+
# block_background_fill='*primary_50'
|
247 |
+
# )
|
248 |
+
|
249 |
+
def zh_prompt_info(text, neg_text, chinese_check):
|
250 |
+
can_raise_info = ""
|
251 |
+
lang_check_label = pipe(text, top_k=1, truncation=True)[0]['label']
|
252 |
+
lang_check_score = pipe(text, top_k=1, truncation=True)[0]['score']
|
253 |
+
neg_lang_check_label = pipe(neg_text, top_k=1, truncation=True)[0]['label']
|
254 |
+
neg_lang_check_score = pipe(neg_text, top_k=1, truncation=True)[0]['score']
|
255 |
+
print(lang_check_label)
|
256 |
+
if lang_check_label == 'zh' and lang_check_score >= 0.85:
|
257 |
+
if not chinese_check:
|
258 |
+
chinese_check = True
|
259 |
+
can_raise_info = "zh"
|
260 |
+
if neg_lang_check_label == 'en' and neg_lang_check_score >= 0.85:
|
261 |
+
can_raise_info = "invalid"
|
262 |
+
return True, can_raise_info
|
263 |
+
elif lang_check_label == 'en' and lang_check_score >= 0.85:
|
264 |
+
if chinese_check:
|
265 |
+
chinese_check = False
|
266 |
+
can_raise_info = "en"
|
267 |
+
if neg_lang_check_label == 'zh' and neg_lang_check_score >= 0.85:
|
268 |
+
can_raise_info = "invalid"
|
269 |
+
return False, can_raise_info
|
270 |
+
return chinese_check, can_raise_info
|
271 |
+
def mult_thread_img2img(prompt_box, neg_prompt_box, image_box):
|
272 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=12000) as executor:
|
273 |
+
future = executor.submit(real_img2img_to_anime, prompt_box, neg_prompt_box, image_box)
|
274 |
+
image1, image2, image3, image4 = future.result()
|
275 |
+
return image1, image2, image3, image4
|
276 |
+
def mult_thread_scribble(prompt_box, neg_prompt_box, image_box):
|
277 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=12000) as executor:
|
278 |
+
future = executor.submit(scribble_to_image, prompt_box, neg_prompt_box, image_box)
|
279 |
+
image1, image2, image3, image4 = future.result()
|
280 |
+
return image1, image2, image3, image4
|
281 |
+
def mult_thread_lang_class(prompt_box, neg_prompt_box, chinese_check):
|
282 |
+
|
283 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=12000) as executor:
|
284 |
+
future = executor.submit(zh_prompt_info, prompt_box, neg_prompt_box, chinese_check)
|
285 |
+
chinese_check, can_raise_info = future.result()
|
286 |
+
if can_raise_info == "zh":
|
287 |
+
gr.Info("Chinese Language Detected, Switching to Chinese Prompt Mode")
|
288 |
+
elif can_raise_info == "en":
|
289 |
+
gr.Info("English Language Detected, Disabling Chinese Prompt Mode")
|
290 |
+
return chinese_check
|
291 |
|
292 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}", title="ShellAI Apps") as iface:
|
293 |
with gr.Tab("Animefier"):
|
294 |
with gr.Row(equal_height=True):
|
295 |
with gr.Column():
|
296 |
with gr.Row(equal_height=True):
|
297 |
+
with gr.Column(scale=4):
|
298 |
+
prompt_box = gr.Textbox(label="Prompt", placeholder="Enter a prompt", lines=3)
|
299 |
+
neg_prompt_box = gr.Textbox(label="Negative Prompt", placeholder="Enter a negative prompt(things you don't want to include in the generated image)", lines=3)
|
300 |
+
with gr.Row(equal_height=True):
|
301 |
+
chinese_check = gr.Checkbox(label="Chinese Prompt Mode", info="Click here to enable Chinese Prompting(点此触发中文提示词输入)")
|
302 |
|
303 |
image_box = gr.Image(label="Input Image", height=350)
|
304 |
gen_btn = gr.Button(value="Generate")
|
|
|
308 |
global image2
|
309 |
global image3
|
310 |
global image4
|
311 |
+
image1 = gr.Image(label="Result 1")
|
312 |
+
image2 = gr.Image(label="Result 2")
|
313 |
+
image3 = gr.Image(label="Result 3")
|
314 |
+
image4 = gr.Image(label="Result 4")
|
315 |
+
|
316 |
+
|
317 |
+
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)
|
318 |
+
gr.on(triggers=[prompt_box.submit, gen_btn.click],fn=mult_thread_img2img, inputs=[prompt_box, neg_prompt_box, image_box], outputs=[image1, image2, image3, image4])
|
|
|
|
|
|
|
319 |
|
320 |
with gr.Tab("AniSketch"):
|
321 |
with gr.Row(equal_height=True):
|
322 |
with gr.Column():
|
323 |
with gr.Row(equal_height=True):
|
324 |
+
with gr.Column(scale=4):
|
325 |
+
prompt_box = gr.Textbox(label="Prompt", placeholder="Enter a prompt", lines=3)
|
326 |
+
neg_prompt_box = gr.Textbox(label="Negative Prompt", placeholder="Enter a negative prompt(things you don't want to include in the generated image)", lines=3)
|
327 |
+
with gr.Row(equal_height=True):
|
328 |
+
chinese_check = gr.Checkbox(label="Chinese Prompt Mode", info="Click here to enable Chinese Prompting(点此触发中文提示词输入)")
|
329 |
|
330 |
image_box = gr.Image(label="Input Image", height=350)
|
331 |
gen_btn = gr.Button(value="Generate")
|
332 |
with gr.Row(equal_height=True):
|
333 |
+
image1 = gr.Image(label="Result 1")
|
334 |
+
image2 = gr.Image(label="Result 2")
|
335 |
+
image3 = gr.Image(label="Result 3")
|
336 |
+
image4 = gr.Image(label="Result 4")
|
337 |
|
338 |
+
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)
|
339 |
+
gr.on(triggers=[prompt_box.submit, gen_btn.click],fn=mult_thread_scribble, inputs=[prompt_box, neg_prompt_box, image_box], outputs=[image1, image2, image3, image4])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
|
|
|
341 |
|
342 |
+
# gen_btn.click(mult_thread, [prompt_box, image_box, chinese_check], [image1, image2, image3, image4, chinese_check])
|
343 |
+
iface.dependencies[0]["show_progress"] = "hidden"
|
344 |
iface.launch(debug=True, share=True, auth=["shenrym", "shjdqw%23-sw2&"])
|