Spaces:
Running
Running
liuyizhang
commited on
Commit
·
82edc6e
1
Parent(s):
6c492ea
update app.py
Browse files- app.py +53 -6
- requirements.txt +2 -1
app.py
CHANGED
@@ -8,6 +8,11 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
8 |
from loguru import logger
|
9 |
|
10 |
from utils import get_tmt_client, getTextTrans_tmt
|
|
|
|
|
|
|
|
|
|
|
11 |
tmt_client = get_tmt_client()
|
12 |
|
13 |
# language_translation_model = hub.Module(directory=f'./baidu_translate')
|
@@ -33,6 +38,8 @@ space_ids = {
|
|
33 |
"spaces/runwayml/stable-diffusion-v1-5": "SD 1.5",
|
34 |
"spaces/stabilityai/stable-diffusion-1": "SD 1.0",
|
35 |
"dalle_mini_tab": "Dalle mini",
|
|
|
|
|
36 |
"spaces/IDEA-CCNL/Taiyi-Stable-Diffusion-Chinese": "Taiyi(太乙)",
|
37 |
}
|
38 |
|
@@ -135,6 +142,7 @@ start_work = """async() => {
|
|
135 |
valueSetter.call(element, value);
|
136 |
}
|
137 |
}
|
|
|
138 |
window['tab_advanced'] = 0;
|
139 |
|
140 |
var gradioEl = document.querySelector('body > gradio-app').shadowRoot;
|
@@ -144,8 +152,10 @@ start_work = """async() => {
|
|
144 |
|
145 |
if (typeof window['gradioEl'] === 'undefined') {
|
146 |
window['gradioEl'] = gradioEl;
|
|
|
147 |
tabitems = window['gradioEl'].querySelectorAll('.tabitem');
|
148 |
tabitems_title = window['gradioEl'].querySelectorAll('#tab_demo')[0].children[0].children[0].children;
|
|
|
149 |
window['dalle_mini_block'] = null;
|
150 |
window['dalle_mini_iframe'] = null;
|
151 |
for (var i = 0; i < tabitems.length; i++) {
|
@@ -163,6 +173,15 @@ start_work = """async() => {
|
|
163 |
} else if (tabitems_title[i].innerText.indexOf('SD 2') >= 0) {
|
164 |
tabitems[i].children[0].children[1].children[3].children[0].click();
|
165 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
} else if (tabitems_title[i].innerText.indexOf('Taiyi') >= 0) {
|
167 |
tabitems[i].children[0].children[0].children[1].style.display='none';
|
168 |
tabitems[i].children[0].children[0].children[0].children[0].children[1].style.display='none';
|
@@ -170,7 +189,15 @@ start_work = """async() => {
|
|
170 |
tabitems[i].childNodes[0].children[0].children[1].style.display='none';
|
171 |
} else if (tabitems_title[i].innerText.indexOf('Dalle mini') >= 0) {
|
172 |
window['dalle_mini_block']= tabitems[i];
|
173 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
}
|
175 |
|
176 |
tab_demo = window['gradioEl'].querySelectorAll('#tab_demo')[0];
|
@@ -186,6 +213,7 @@ start_work = """async() => {
|
|
186 |
}
|
187 |
page1.style.display = "none";
|
188 |
page2.style.display = "block";
|
|
|
189 |
prompt_work = window['gradioEl'].querySelectorAll('#prompt_work');
|
190 |
for (var i = 0; i < prompt_work.length; i++) {
|
191 |
prompt_work[i].style.display='none';
|
@@ -226,9 +254,18 @@ start_work = """async() => {
|
|
226 |
if (tabitems_title[i].innerText.indexOf('SD') >= 0) {
|
227 |
text_value = window['gradioEl'].querySelectorAll('#prompt_work')[0].querySelectorAll('textarea')[0].value;
|
228 |
inputText = tabitems[i].children[0].children[1].children[0].querySelectorAll('.gr-text-input')[0];
|
|
|
|
|
|
|
229 |
} else if (tabitems_title[i].innerText.indexOf('Taiyi') >= 0) {
|
230 |
text_value = window['gradioEl'].querySelectorAll('#prompt_work_zh')[0].querySelectorAll('textarea')[0].value;
|
231 |
inputText = tabitems[i].children[0].children[0].children[1].querySelectorAll('.gr-text-input')[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
}
|
233 |
if (inputText) {
|
234 |
setNativeValue(inputText, text_value);
|
@@ -239,7 +276,7 @@ start_work = """async() => {
|
|
239 |
setTimeout(function() {
|
240 |
btns = window['gradioEl'].querySelectorAll('button');
|
241 |
for (var i = 0; i < btns.length; i++) {
|
242 |
-
if (['Generate image','Run',
|
243 |
btns[i].click();
|
244 |
}
|
245 |
}
|
@@ -272,10 +309,21 @@ switch_tab_advanced = """async() => {
|
|
272 |
if (j != 1) {
|
273 |
tabitems[i].childNodes[0].children[1].children[j].style.display=action;
|
274 |
}
|
275 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
} else if (tabitems_title[i].innerText.indexOf('Taiyi') >= 0) {
|
277 |
tabitems[i].children[0].children[0].children[1].style.display=action;
|
278 |
-
}
|
|
|
|
|
|
|
|
|
279 |
}
|
280 |
return false;
|
281 |
}"""
|
@@ -391,5 +439,4 @@ with gr.Blocks(title='Text-to-Image') as demo:
|
|
391 |
draw_btn_0.click(fn=prompt_draw_2, inputs=[prompt_input0], outputs=[prompt_work, prompt_work_zh])
|
392 |
draw_btn_1.click(fn=prompt_draw_2, inputs=[prompt_input1], outputs=[prompt_work, prompt_work_zh])
|
393 |
|
394 |
-
demo.queue()
|
395 |
-
demo.launch()
|
|
|
8 |
from loguru import logger
|
9 |
|
10 |
from utils import get_tmt_client, getTextTrans_tmt
|
11 |
+
import subprocess
|
12 |
+
|
13 |
+
result = subprocess.run(['pip', 'list'], check=True)
|
14 |
+
print(f'pip list = {result}')
|
15 |
+
|
16 |
tmt_client = get_tmt_client()
|
17 |
|
18 |
# language_translation_model = hub.Module(directory=f'./baidu_translate')
|
|
|
38 |
"spaces/runwayml/stable-diffusion-v1-5": "SD 1.5",
|
39 |
"spaces/stabilityai/stable-diffusion-1": "SD 1.0",
|
40 |
"dalle_mini_tab": "Dalle mini",
|
41 |
+
"spaces/ai-forever/Kandinsky2.1": "Kandinsky2.1",
|
42 |
+
"spaces/yizhangliu/openjourney-v2": "openjourney",
|
43 |
"spaces/IDEA-CCNL/Taiyi-Stable-Diffusion-Chinese": "Taiyi(太乙)",
|
44 |
}
|
45 |
|
|
|
142 |
valueSetter.call(element, value);
|
143 |
}
|
144 |
}
|
145 |
+
|
146 |
window['tab_advanced'] = 0;
|
147 |
|
148 |
var gradioEl = document.querySelector('body > gradio-app').shadowRoot;
|
|
|
152 |
|
153 |
if (typeof window['gradioEl'] === 'undefined') {
|
154 |
window['gradioEl'] = gradioEl;
|
155 |
+
|
156 |
tabitems = window['gradioEl'].querySelectorAll('.tabitem');
|
157 |
tabitems_title = window['gradioEl'].querySelectorAll('#tab_demo')[0].children[0].children[0].children;
|
158 |
+
|
159 |
window['dalle_mini_block'] = null;
|
160 |
window['dalle_mini_iframe'] = null;
|
161 |
for (var i = 0; i < tabitems.length; i++) {
|
|
|
173 |
} else if (tabitems_title[i].innerText.indexOf('SD 2') >= 0) {
|
174 |
tabitems[i].children[0].children[1].children[3].children[0].click();
|
175 |
}
|
176 |
+
} else if (tabitems_title[i].innerText.indexOf('ernie') >= 0) {
|
177 |
+
tabitems[i].children[0].children[0].style.display='none';
|
178 |
+
tabitems[i].children[0].children[1].children[0].style.display='none';
|
179 |
+
tabitems[i].children[0].children[1].children[1].style.display='none';
|
180 |
+
tabitems[i].children[0].children[1].children[4].style.display='none';
|
181 |
+
tabitems[i].children[0].children[1].children[5].style.display='none';
|
182 |
+
tabitems[i].children[0].children[1].children[6].style.display='none';
|
183 |
+
tabitems[i].children[0].children[1].children[7].style.display='none';
|
184 |
+
tabitems[i].children[0].children[1].children[8].style.display='none';
|
185 |
} else if (tabitems_title[i].innerText.indexOf('Taiyi') >= 0) {
|
186 |
tabitems[i].children[0].children[0].children[1].style.display='none';
|
187 |
tabitems[i].children[0].children[0].children[0].children[0].children[1].style.display='none';
|
|
|
189 |
tabitems[i].childNodes[0].children[0].children[1].style.display='none';
|
190 |
} else if (tabitems_title[i].innerText.indexOf('Dalle mini') >= 0) {
|
191 |
window['dalle_mini_block']= tabitems[i];
|
192 |
+
} else if (tabitems_title[i].innerText.indexOf('openjourney') >= 0) {
|
193 |
+
tabitems[i].children[0].children[0].style.display='none';
|
194 |
+
tabitems[i].children[0].children[1].children[0].style.display='none';
|
195 |
+
tabitems[i].children[0].children[1].children[1].children[0].children[1].style.display='none';
|
196 |
+
} else if (tabitems_title[i].innerText.indexOf('Kandinsky') >= 0) {
|
197 |
+
tabitems[i].children[0].children[0].style.display='none';
|
198 |
+
tabitems[i].children[0].children[1].children[0].style.display='none';
|
199 |
+
tabitems[i].children[0].children[1].children[2].style.display='none';
|
200 |
+
}
|
201 |
}
|
202 |
|
203 |
tab_demo = window['gradioEl'].querySelectorAll('#tab_demo')[0];
|
|
|
213 |
}
|
214 |
page1.style.display = "none";
|
215 |
page2.style.display = "block";
|
216 |
+
|
217 |
prompt_work = window['gradioEl'].querySelectorAll('#prompt_work');
|
218 |
for (var i = 0; i < prompt_work.length; i++) {
|
219 |
prompt_work[i].style.display='none';
|
|
|
254 |
if (tabitems_title[i].innerText.indexOf('SD') >= 0) {
|
255 |
text_value = window['gradioEl'].querySelectorAll('#prompt_work')[0].querySelectorAll('textarea')[0].value;
|
256 |
inputText = tabitems[i].children[0].children[1].children[0].querySelectorAll('.gr-text-input')[0];
|
257 |
+
} else if (tabitems_title[i].innerText.indexOf('ernie') >= 0) {
|
258 |
+
text_value = window['gradioEl'].querySelectorAll('#prompt_work_zh')[0].querySelectorAll('textarea')[0].value;
|
259 |
+
inputText = tabitems[i].children[0].children[1].children[0].querySelectorAll('.gr-text-input')[0];
|
260 |
} else if (tabitems_title[i].innerText.indexOf('Taiyi') >= 0) {
|
261 |
text_value = window['gradioEl'].querySelectorAll('#prompt_work_zh')[0].querySelectorAll('textarea')[0].value;
|
262 |
inputText = tabitems[i].children[0].children[0].children[1].querySelectorAll('.gr-text-input')[0];
|
263 |
+
} else if (tabitems_title[i].innerText.indexOf('openjourney') >= 0) {
|
264 |
+
text_value = window['gradioEl'].querySelectorAll('#prompt_work')[0].querySelectorAll('textarea')[0].value;
|
265 |
+
inputText = tabitems[i].children[0].children[1].children[0].children[0].querySelectorAll('.gr-text-input')[0]
|
266 |
+
} else if (tabitems_title[i].innerText.indexOf('Kandinsky') >= 0) {
|
267 |
+
text_value = window['gradioEl'].querySelectorAll('#prompt_work')[0].querySelectorAll('textarea')[0].value;
|
268 |
+
inputText = tabitems[i].children[0].children[1].children[0].children[0].querySelectorAll('.gr-text-input')[0]
|
269 |
}
|
270 |
if (inputText) {
|
271 |
setNativeValue(inputText, text_value);
|
|
|
276 |
setTimeout(function() {
|
277 |
btns = window['gradioEl'].querySelectorAll('button');
|
278 |
for (var i = 0; i < btns.length; i++) {
|
279 |
+
if (['Generate image','Run','生成图像(Generate)','Submit', 'Generate video'].includes(btns[i].innerText)) {
|
280 |
btns[i].click();
|
281 |
}
|
282 |
}
|
|
|
309 |
if (j != 1) {
|
310 |
tabitems[i].childNodes[0].children[1].children[j].style.display=action;
|
311 |
}
|
312 |
+
}
|
313 |
+
} else if (tabitems_title[i].innerText.indexOf('ernie') >= 0) {
|
314 |
+
tabitems[i].children[0].children[1].children[0].style.display=action;
|
315 |
+
tabitems[i].children[0].children[1].children[1].style.display=action;
|
316 |
+
tabitems[i].children[0].children[1].children[4].style.display=action;
|
317 |
+
tabitems[i].children[0].children[1].children[5].style.display=action;
|
318 |
+
tabitems[i].children[0].children[1].children[6].style.display=action;
|
319 |
+
tabitems[i].children[0].children[1].children[7].style.display=action;
|
320 |
} else if (tabitems_title[i].innerText.indexOf('Taiyi') >= 0) {
|
321 |
tabitems[i].children[0].children[0].children[1].style.display=action;
|
322 |
+
} else if (tabitems_title[i].innerText.indexOf('openjourney') >= 0) {
|
323 |
+
tabitems[i].children[0].children[1].children[0].style.display=action;
|
324 |
+
} else if (tabitems_title[i].innerText.indexOf('Kandinsky') >= 0) {
|
325 |
+
tabitems[i].children[0].children[1].children[0].style.display=action;
|
326 |
+
}
|
327 |
}
|
328 |
return false;
|
329 |
}"""
|
|
|
439 |
draw_btn_0.click(fn=prompt_draw_2, inputs=[prompt_input0], outputs=[prompt_work, prompt_work_zh])
|
440 |
draw_btn_1.click(fn=prompt_draw_2, inputs=[prompt_input1], outputs=[prompt_work, prompt_work_zh])
|
441 |
|
442 |
+
demo.queue(concurrency_count=128).launch()
|
|
requirements.txt
CHANGED
@@ -2,8 +2,9 @@ ftfy
|
|
2 |
spacy
|
3 |
transformers
|
4 |
torch
|
5 |
-
gradio
|
6 |
paddlepaddle==2.3.2
|
7 |
paddlehub
|
|
|
8 |
loguru
|
9 |
tencentcloud-sdk-python
|
|
|
2 |
spacy
|
3 |
transformers
|
4 |
torch
|
5 |
+
gradio==3.14.0
|
6 |
paddlepaddle==2.3.2
|
7 |
paddlehub
|
8 |
+
requests
|
9 |
loguru
|
10 |
tencentcloud-sdk-python
|