Spaces:
Runtime error
Runtime error
Add resolution and more style
Browse files
app.py
CHANGED
@@ -7,7 +7,8 @@ model = hub.Module(name='ernie_vilg')
|
|
7 |
language_translation_model = hub.Module(name='baidu_translate')
|
8 |
language_recognition_model = hub.Module(name='baidu_language_recognition')
|
9 |
|
10 |
-
style_list = ['
|
|
|
11 |
|
12 |
tips = {"en": "Tips: The input text will be translated into Chinese for generation",
|
13 |
"jp": "ヒント: 入力テキストは生成のために中国語に翻訳されます",
|
@@ -36,11 +37,12 @@ def translate_language(text_prompts):
|
|
36 |
return {language_tips_text:gr.update(visible=True, value=tips_text), translated_language:text_prompts, trigger_component: gr.update(value=count, visible=False)}
|
37 |
|
38 |
|
39 |
-
def inference(text_prompts, style_indx):
|
40 |
try:
|
41 |
style = style_list[style_indx]
|
|
|
42 |
results = model.generate_image(
|
43 |
-
text_prompts=text_prompts, style=style, visualization=False)
|
44 |
except Exception as e:
|
45 |
error_text = str(e)
|
46 |
return {status_text:error_text, gallery:None}
|
@@ -273,7 +275,11 @@ with block:
|
|
273 |
rounded=(False, True, True, False),
|
274 |
)
|
275 |
language_tips_text = gr.Textbox(label="language tips", show_label=False, visible=False, max_lines=1)
|
276 |
-
styles = gr.Dropdown(label="风格(style)", choices=['
|
|
|
|
|
|
|
|
|
277 |
gallery = gr.Gallery(
|
278 |
label="Generated images", show_label=False, elem_id="gallery"
|
279 |
).style(grid=[2, 3], height="auto")
|
@@ -292,7 +298,7 @@ with block:
|
|
292 |
|
293 |
text.submit(translate_language, inputs=[text], outputs=[language_tips_text, status_text, trigger_component, translated_language])
|
294 |
btn.click(translate_language, inputs=[text], outputs=[language_tips_text, status_text, trigger_component, translated_language])
|
295 |
-
trigger_component.change(fn=inference, inputs=[translated_language, styles], outputs=[status_text, gallery])
|
296 |
gr.HTML(
|
297 |
"""
|
298 |
<div class="prompt">
|
|
|
7 |
language_translation_model = hub.Module(name='baidu_translate')
|
8 |
language_recognition_model = hub.Module(name='baidu_language_recognition')
|
9 |
|
10 |
+
style_list = ['古风', '油画', '水彩', '卡通', '二次元', '浮世绘', '蒸汽波艺术', 'low poly', '像素风格', '概念艺术', '未来主义', '赛博朋克', '写实风格', '洛丽塔风格', '巴洛克风格', '超现实主义', '探索无限']
|
11 |
+
resolution_list = ['1024*1024', '1024*1536', '1536*1024']
|
12 |
|
13 |
tips = {"en": "Tips: The input text will be translated into Chinese for generation",
|
14 |
"jp": "ヒント: 入力テキストは生成のために中国語に翻訳されます",
|
|
|
37 |
return {language_tips_text:gr.update(visible=True, value=tips_text), translated_language:text_prompts, trigger_component: gr.update(value=count, visible=False)}
|
38 |
|
39 |
|
40 |
+
def inference(text_prompts, style_indx, resolution_indx):
|
41 |
try:
|
42 |
style = style_list[style_indx]
|
43 |
+
resolution = style_list[resolution_indx]
|
44 |
results = model.generate_image(
|
45 |
+
text_prompts=text_prompts, style=style, resolution=resolution, visualization=False)
|
46 |
except Exception as e:
|
47 |
error_text = str(e)
|
48 |
return {status_text:error_text, gallery:None}
|
|
|
275 |
rounded=(False, True, True, False),
|
276 |
)
|
277 |
language_tips_text = gr.Textbox(label="language tips", show_label=False, visible=False, max_lines=1)
|
278 |
+
styles = gr.Dropdown(label="风格(style)", choices=['古风(Ancient Style)', '油画(Oil painting)', '水彩(Watercolor)',
|
279 |
+
'卡通(Cartoon)', '二次元(Anime)', '浮世绘(Ukiyoe)', '蒸汽波艺术(Vaporwave)', 'low poly',
|
280 |
+
'像素风格(Pixel Style)', '概念艺术(Conceptual Art)', '未来主义(Futurism)', '赛博朋克(Cyberpunk)', '写实风格(Realistic style)',
|
281 |
+
'洛丽塔风格(Lolita style)', '巴洛克风格(Baroque style)', '超现实主义(Surrealism)', '探索无限(Explore infinity)'], value='探索无限(Explore infinity)', type="index")
|
282 |
+
resolutions = gr.Dropdown(label="分辨率(resolution)", choices=resolution_list, value='1024*1024', type="index")
|
283 |
gallery = gr.Gallery(
|
284 |
label="Generated images", show_label=False, elem_id="gallery"
|
285 |
).style(grid=[2, 3], height="auto")
|
|
|
298 |
|
299 |
text.submit(translate_language, inputs=[text], outputs=[language_tips_text, status_text, trigger_component, translated_language])
|
300 |
btn.click(translate_language, inputs=[text], outputs=[language_tips_text, status_text, trigger_component, translated_language])
|
301 |
+
trigger_component.change(fn=inference, inputs=[translated_language, styles, resolutions], outputs=[status_text, gallery])
|
302 |
gr.HTML(
|
303 |
"""
|
304 |
<div class="prompt">
|