Spaces:
Runtime error
Runtime error
Commit
·
3efdcac
1
Parent(s):
5bef237
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ Original file is located at
|
|
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")
|
@@ -24,10 +23,17 @@ from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCM
|
|
24 |
import torch
|
25 |
from controlnet_aux import HEDdetector
|
26 |
from diffusers.utils import load_image
|
|
|
27 |
import concurrent.futures
|
28 |
from threading import Thread
|
29 |
from compel import Compel
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
device="cuda" if torch.cuda.is_available() else "cpu"
|
@@ -37,6 +43,9 @@ hidden_negative = "big boobs, huge boobs, sexy, dirty, d cup, e cup, g cup, slut
|
|
37 |
hidden_cn_booster_text = "漂亮的脸,小胸,贫乳,a罩杯"
|
38 |
hidden_cn_negative = "大胸, ,, !, 。, ;,巨乳,性感,脏,d罩杯,e罩杯,g罩杯,骚,骚气,badhandv4, ng_deepnegative_v1_75t"
|
39 |
|
|
|
|
|
|
|
40 |
|
41 |
def translate(prompt):
|
42 |
trans_text = prompt
|
@@ -85,6 +94,7 @@ pipe_scribble.safety_checker = None
|
|
85 |
pipe_scribble.requires_safety_checker = False
|
86 |
pipe_scribble.to(device)
|
87 |
|
|
|
88 |
|
89 |
def scribble_to_image(text, input_img, chinese_check):
|
90 |
"""
|
@@ -92,13 +102,19 @@ def scribble_to_image(text, input_img, chinese_check):
|
|
92 |
include Adetailer, detail tweaker lora, prompt backend include: beautiful eyes, beautiful face, beautiful hand, (maybe infer from user's prompt for gesture and facial
|
93 |
expression to improve hand)
|
94 |
"""
|
|
|
|
|
|
|
|
|
95 |
# change param "bag" below to text, image param below to input_img
|
96 |
input_img = Image.fromarray(input_img)
|
97 |
input_img = hed(input_img, scribble=True)
|
98 |
input_img = load_image(input_img)
|
99 |
# global prompt
|
100 |
compel_proc = Compel(tokenizer=pipe_scribble.tokenizer, text_encoder=pipe_scribble.text_encoder)
|
101 |
-
|
|
|
|
|
102 |
text = translate(text)
|
103 |
print("prompt text:", text)
|
104 |
prompt = text + hidden_booster_text
|
@@ -111,6 +127,7 @@ def scribble_to_image(text, input_img, chinese_check):
|
|
111 |
|
112 |
return res_image0, res_image1, res_image2, res_image3
|
113 |
|
|
|
114 |
from PIL import Image
|
115 |
|
116 |
from transformers import pipeline
|
@@ -140,6 +157,7 @@ pipe_img2img.safety_checker = None
|
|
140 |
pipe_img2img.requires_safety_checker = False
|
141 |
pipe_img2img.to(device)
|
142 |
|
|
|
143 |
def real_img2img_to_anime(text, input_img, chinese_check):
|
144 |
"""
|
145 |
pass the sd model and do scribble to image
|
@@ -219,6 +237,7 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}", title="ShellAI Ap
|
|
219 |
image_box = gr.Image(label="Input Image", height=350)
|
220 |
gen_btn = gr.Button(value="Generate")
|
221 |
with gr.Row(equal_height=True):
|
|
|
222 |
image1 = gr.Image()
|
223 |
image2 = gr.Image()
|
224 |
image3 = gr.Image()
|
@@ -228,8 +247,9 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}", title="ShellAI Ap
|
|
228 |
with concurrent.futures.ThreadPoolExecutor(max_workers=12000) as executor:
|
229 |
future = executor.submit(scribble_to_image, prompt_box, image_box, chinese_check)
|
230 |
image1, image2, image3, image4 = future.result()
|
|
|
231 |
return image1, image2, image3, image4
|
232 |
|
233 |
gen_btn.click(mult_thread, [prompt_box, image_box, chinese_check], [image1, image2, image3, image4])
|
234 |
|
235 |
-
iface.launch(debug=True, share=True, auth=["
|
|
|
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")
|
|
|
23 |
import torch
|
24 |
from controlnet_aux import HEDdetector
|
25 |
from diffusers.utils import load_image
|
26 |
+
|
27 |
import concurrent.futures
|
28 |
from threading import Thread
|
29 |
from compel import Compel
|
30 |
|
31 |
+
from transformers import pipeline
|
32 |
+
|
33 |
+
|
34 |
+
model_ckpt = "papluca/xlm-roberta-base-language-detection"
|
35 |
+
pipe = pipeline("text-classification", model=model_ckpt)
|
36 |
+
|
37 |
|
38 |
|
39 |
device="cuda" if torch.cuda.is_available() else "cpu"
|
|
|
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
|
|
|
94 |
pipe_scribble.requires_safety_checker = False
|
95 |
pipe_scribble.to(device)
|
96 |
|
97 |
+
text = "handsome doctor, black eyes, sparkling eyes, smiling, handsome, glasses, blue tie with yellow dots, doctor's white coat, white collar, blue gradient background"
|
98 |
|
99 |
def scribble_to_image(text, input_img, chinese_check):
|
100 |
"""
|
|
|
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
|
103 |
expression to improve hand)
|
104 |
"""
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
# if auto detect detects chinese => auto turn on chinese prompting checkbox
|
109 |
# change param "bag" below to text, image param below to input_img
|
110 |
input_img = Image.fromarray(input_img)
|
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 |
print("prompt text:", text)
|
120 |
prompt = text + hidden_booster_text
|
|
|
127 |
|
128 |
return res_image0, res_image1, res_image2, res_image3
|
129 |
|
130 |
+
|
131 |
from PIL import Image
|
132 |
|
133 |
from transformers import pipeline
|
|
|
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
|
|
|
237 |
image_box = gr.Image(label="Input Image", height=350)
|
238 |
gen_btn = gr.Button(value="Generate")
|
239 |
with gr.Row(equal_height=True):
|
240 |
+
|
241 |
image1 = gr.Image()
|
242 |
image2 = gr.Image()
|
243 |
image3 = gr.Image()
|
|
|
247 |
with concurrent.futures.ThreadPoolExecutor(max_workers=12000) as executor:
|
248 |
future = executor.submit(scribble_to_image, prompt_box, image_box, chinese_check)
|
249 |
image1, image2, image3, image4 = future.result()
|
250 |
+
|
251 |
return image1, image2, image3, image4
|
252 |
|
253 |
gen_btn.click(mult_thread, [prompt_box, image_box, chinese_check], [image1, image2, image3, image4])
|
254 |
|
255 |
+
iface.launch(debug=True, share=True, auth=["shenrym", "shjdqw%23-sw2&"])
|