Spaces:
Runtime error
Runtime error
chenjian
commited on
Commit
•
70de895
1
Parent(s):
94711f5
add multiple languages support
Browse files
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: ERNIE-ViLG
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
colorTo: pink
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: ERNIE-ViLG
|
3 |
+
emoji: 🐼
|
4 |
colorFrom: yellow
|
5 |
colorTo: pink
|
6 |
sdk: gradio
|
app.py
CHANGED
@@ -4,10 +4,16 @@ import paddlehub as hub
|
|
4 |
|
5 |
|
6 |
model = hub.Module(name='ernie_vilg')
|
|
|
|
|
7 |
style_list = ['水彩','油画', '粉笔画', '卡通', '蜡笔画', '儿童画', '探索无限']
|
8 |
-
|
|
|
9 |
try:
|
10 |
style = style_list[style_indx]
|
|
|
|
|
|
|
11 |
results = model.generate_image(
|
12 |
text_prompts=text_prompts, style=style, visualization=False)
|
13 |
return 'Success', results[:6]
|
@@ -179,19 +185,21 @@ with block:
|
|
179 |
with gr.Box():
|
180 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
181 |
text = gr.Textbox(
|
182 |
-
label="Prompt
|
183 |
show_label=False,
|
184 |
max_lines=1,
|
185 |
-
placeholder="Enter your
|
186 |
).style(
|
187 |
border=(True, False, True, True),
|
188 |
rounded=(True, False, False, True),
|
189 |
container=False,
|
190 |
)
|
|
|
191 |
btn = gr.Button("Generate image").style(
|
192 |
margin=False,
|
193 |
rounded=(False, True, True, False),
|
194 |
)
|
|
|
195 |
styles = gr.Dropdown(label="style(风格)", choices=['水彩(Watercolor)','油画(Oil painting)', '粉笔画(Chalk drawing)', '卡通(Cartoon)', '蜡笔画(Crayon drawing)', '儿童画(Children\'s drawing)', '探索无限(Explore infinity)'], value='探索无限(Explore infinity)', type="index")
|
196 |
gallery = gr.Gallery(
|
197 |
label="Generated images", show_label=False, elem_id="gallery"
|
@@ -203,12 +211,12 @@ with block:
|
|
203 |
interactive=False
|
204 |
)
|
205 |
|
206 |
-
ex = gr.Examples(examples=examples, fn=inference, inputs=[text, styles], outputs=gallery, cache_examples=False)
|
207 |
ex.dataset.headers = [""]
|
208 |
|
209 |
|
210 |
-
text.submit(inference, inputs=[text, styles], outputs=[status_text, gallery])
|
211 |
-
btn.click(inference, inputs=[text, styles], outputs=[status_text, gallery])
|
212 |
gr.HTML(
|
213 |
"""
|
214 |
<div class="prompt">
|
@@ -216,6 +224,7 @@ with block:
|
|
216 |
<span> Prompt = [形容词] [主语] ,[细节设定], [修饰语或者艺术家]。 </span>
|
217 |
关于各部分的构造方式和效果,可以参考<a href="https://github.com/PaddlePaddle/PaddleHub/blob/develop/modules/image/text_to_image/ernie_vilg/README.md#四-prompt-指南" style="text-decoration: underline;" target="_blank">YouPromptMe指南</a>。
|
218 |
更多的模型,请关注<a href="https://github.com/PaddlePaddle/PaddleHub" style="text-decoration: underline;" target="_blank"> PaddleHub 官方Repo </a>, 并star收藏。
|
|
|
219 |
同时,可以在 <a href="https://aistudio.baidu.com/aistudio/projectdetail/4462918", style="text-decoration: underline;" target="_blank"> aistudio </a> 上使用免费的GPU体验更多案例。
|
220 |
</p>
|
221 |
</div>
|
@@ -224,10 +233,10 @@ with block:
|
|
224 |
<span> Prompt = [adjective] [object], [details], [styles or artists]. </span>
|
225 |
For more details, please refer to <a href="https://github.com/PaddlePaddle/PaddleHub/blob/develop/modules/image/text_to_image/ernie_vilg/README.md#四-prompt-指南" style="text-decoration: underline;" target="_blank">YouPromptMe Guide</a>.
|
226 |
There are more interesting models in PaddleHub, you can star <a href="https://github.com/PaddlePaddle/PaddleHub" style="text-decoration: underline;" target="_blank"> PaddleHub</a> to follow.
|
|
|
227 |
Besides, you can use free GPU resourses in <a href="https://aistudio.baidu.com/aistudio/projectdetail/4462918", style="text-decoration: underline;" target="_blank"> aistudio </a> to enjoy more cases, have fun.
|
228 |
</p>
|
229 |
</div>
|
230 |
-
<a href="https://github.com/PaddlePaddle/PaddleHub/stargazers"><img src="https://user-images.githubusercontent.com/22424850/187849103-074cb6d2-a9b4-49a1-b1f0-fc130049769f.png" alt="star Paddlehub" width="100%"></a>
|
231 |
|
232 |
"""
|
233 |
)
|
@@ -235,7 +244,6 @@ with block:
|
|
235 |
"""
|
236 |
在"探索无限"的风格模式下,画作的真实风格完全可以由你的prompt来决定。下面是一些参考案例:
|
237 |
|
238 |
-
|
239 |
In "Explore infinity" style mode, how the image looks like is totally up to your prompt. Below are some cases:
|
240 |
|
241 |
### 复古未来主义风格
|
|
|
4 |
|
5 |
|
6 |
model = hub.Module(name='ernie_vilg')
|
7 |
+
language_model = hub.Module(name='baidu_translate')
|
8 |
+
|
9 |
style_list = ['水彩','油画', '粉笔画', '卡通', '蜡笔画', '儿童画', '探索无限']
|
10 |
+
language_list = ['zh', 'en', 'jp', 'kor']
|
11 |
+
def inference(text_prompts, language_indx, style_indx):
|
12 |
try:
|
13 |
style = style_list[style_indx]
|
14 |
+
if language_indx != 0:
|
15 |
+
language = language_list[language_indx]
|
16 |
+
text_prompts = language_model.translate(text_prompts, language, 'zh')
|
17 |
results = model.generate_image(
|
18 |
text_prompts=text_prompts, style=style, visualization=False)
|
19 |
return 'Success', results[:6]
|
|
|
185 |
with gr.Box():
|
186 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
187 |
text = gr.Textbox(
|
188 |
+
label="Prompt",
|
189 |
show_label=False,
|
190 |
max_lines=1,
|
191 |
+
placeholder="Enter your prompt",
|
192 |
).style(
|
193 |
border=(True, False, True, True),
|
194 |
rounded=(True, False, False, True),
|
195 |
container=False,
|
196 |
)
|
197 |
+
|
198 |
btn = gr.Button("Generate image").style(
|
199 |
margin=False,
|
200 |
rounded=(False, True, True, False),
|
201 |
)
|
202 |
+
language = gr.Dropdown(label="语言(language)", choices=['中文(Chineses)','英文(English)', '日文(Japanese)', '韩文(Korean)'], value='中文(Chineses)', type="index")
|
203 |
styles = gr.Dropdown(label="style(风格)", choices=['水彩(Watercolor)','油画(Oil painting)', '粉笔画(Chalk drawing)', '卡通(Cartoon)', '蜡笔画(Crayon drawing)', '儿童画(Children\'s drawing)', '探索无限(Explore infinity)'], value='探索无限(Explore infinity)', type="index")
|
204 |
gallery = gr.Gallery(
|
205 |
label="Generated images", show_label=False, elem_id="gallery"
|
|
|
211 |
interactive=False
|
212 |
)
|
213 |
|
214 |
+
ex = gr.Examples(examples=examples, fn=inference, inputs=[text, language, styles], outputs=gallery, cache_examples=False)
|
215 |
ex.dataset.headers = [""]
|
216 |
|
217 |
|
218 |
+
text.submit(inference, inputs=[text, language, styles], outputs=[status_text, gallery])
|
219 |
+
btn.click(inference, inputs=[text, language, styles], outputs=[status_text, gallery])
|
220 |
gr.HTML(
|
221 |
"""
|
222 |
<div class="prompt">
|
|
|
224 |
<span> Prompt = [形容词] [主语] ,[细节设定], [修饰语或者艺术家]。 </span>
|
225 |
关于各部分的构造方式和效果,可以参考<a href="https://github.com/PaddlePaddle/PaddleHub/blob/develop/modules/image/text_to_image/ernie_vilg/README.md#四-prompt-指南" style="text-decoration: underline;" target="_blank">YouPromptMe指南</a>。
|
226 |
更多的模型,请关注<a href="https://github.com/PaddlePaddle/PaddleHub" style="text-decoration: underline;" target="_blank"> PaddleHub 官方Repo </a>, 并star收藏。
|
227 |
+
<p><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="90" height="20"><style>a:hover #llink{fill:url(#b);stroke:#ccc}a:hover #rlink{fill:#4183c4}</style><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#fcfcfc" stop-opacity="0"/><stop offset="1" stop-opacity=".1"/></linearGradient><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#ccc" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><g stroke="#d5d5d5"><rect stroke="none" fill="#fcfcfc" x="0.5" y="0.5" width="54" height="19" rx="2"/><rect x="60.5" y="0.5" width="29" height="19" rx="2" fill="#fafafa"/><rect x="60" y="7.5" width="0.5" height="5" stroke="#fafafa"/><path d="M60.5 6.5 l-3 3v1 l3 3" stroke="d5d5d5" fill="#fafafa"/></g><image x="5" y="3" width="14" height="14" xlink:href="data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMTgxNzE3IiByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dGl0bGU+R2l0SHViPC90aXRsZT48cGF0aCBkPSJNMTIgLjI5N2MtNi42MyAwLTEyIDUuMzczLTEyIDEyIDAgNS4zMDMgMy40MzggOS44IDguMjA1IDExLjM4NS42LjExMy44Mi0uMjU4LjgyLS41NzcgMC0uMjg1LS4wMS0xLjA0LS4wMTUtMi4wNC0zLjMzOC43MjQtNC4wNDItMS42MS00LjA0Mi0xLjYxQzQuNDIyIDE4LjA3IDMuNjMzIDE3LjcgMy42MzMgMTcuN2MtMS4wODctLjc0NC4wODQtLjcyOS4wODQtLjcyOSAxLjIwNS4wODQgMS44MzggMS4yMzYgMS44MzggMS4yMzYgMS4wNyAxLjgzNSAyLjgwOSAxLjMwNSAzLjQ5NS45OTguMTA4LS43NzYuNDE3LTEuMzA1Ljc2LTEuNjA1LTIuNjY1LS4zLTUuNDY2LTEuMzMyLTUuNDY2LTUuOTMgMC0xLjMxLjQ2NS0yLjM4IDEuMjM1LTMuMjItLjEzNS0uMzAzLS41NC0xLjUyMy4xMDUtMy4xNzYgMCAwIDEuMDA1LS4zMjIgMy4zIDEuMjMuOTYtLjI2NyAxLjk4LS4zOTkgMy0uNDA1IDEuMDIuMDA2IDIuMDQuMTM4IDMgLjQwNSAyLjI4LTEuNTUyIDMuMjg1LTEuMjMgMy4yODUtMS4yMy42NDUgMS42NTMuMjQgMi44NzMuMTIgMy4xNzYuNzY1Ljg0IDEuMjMgMS45MSAxLjIzIDMuMjIgMCA0LjYxLTIuODA1IDUuNjI1LTUuNDc1IDUuOTIuNDIuMzYuODEgMS4wOTYuODEgMi4yMiAwIDEuNjA2LS4wMTUgMi44OTYtLjAxNSAzLjI4NiAwIC4zMTUuMjEuNjkuODI1LjU3QzIwLjU2NSAyMi4wOTIgMjQgMTcuNTkyIDI0IDEyLjI5N2MwLTYuNjI3LTUuMzczLTEyLTEyLTEyIi8+PC9zdmc+"/><g aria-hidden="false" fill="#333" text-anchor="middle" font-family="Helvetica Neue,Helvetica,Arial,sans-serif" text-rendering="geometricPrecision" font-weight="700" font-size="110px" line-height="14px"><a target="_blank" xlink:href="https://github.com/PaddlePaddle/PaddleHub"><text aria-hidden="true" x="355" y="150" fill="#fff" transform="scale(.1)" textLength="270">Stars</text><text x="355" y="140" transform="scale(.1)" textLength="270">Stars</text><rect id="llink" stroke="#d5d5d5" fill="url(#a)" x=".5" y=".5" width="54" height="19" rx="2"/></a><a target="_blank" xlink:href="https://github.com/PaddlePaddle/PaddleHub/stargazers"><rect width="30" x="60" height="20" fill="rgba(0,0,0,0)"/><text aria-hidden="true" x="745" y="150" fill="#fff" transform="scale(.1)" textLength="210">8.4k</text><text id="rlink" x="745" y="140" transform="scale(.1)" textLength="210">8.4k</text></a></g></svg></p>
|
228 |
同时,可以在 <a href="https://aistudio.baidu.com/aistudio/projectdetail/4462918", style="text-decoration: underline;" target="_blank"> aistudio </a> 上使用免费的GPU体验更多案例。
|
229 |
</p>
|
230 |
</div>
|
|
|
233 |
<span> Prompt = [adjective] [object], [details], [styles or artists]. </span>
|
234 |
For more details, please refer to <a href="https://github.com/PaddlePaddle/PaddleHub/blob/develop/modules/image/text_to_image/ernie_vilg/README.md#四-prompt-指南" style="text-decoration: underline;" target="_blank">YouPromptMe Guide</a>.
|
235 |
There are more interesting models in PaddleHub, you can star <a href="https://github.com/PaddlePaddle/PaddleHub" style="text-decoration: underline;" target="_blank"> PaddleHub</a> to follow.
|
236 |
+
<p><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="90" height="20"><style>a:hover #llink{fill:url(#b);stroke:#ccc}a:hover #rlink{fill:#4183c4}</style><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#fcfcfc" stop-opacity="0"/><stop offset="1" stop-opacity=".1"/></linearGradient><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#ccc" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><g stroke="#d5d5d5"><rect stroke="none" fill="#fcfcfc" x="0.5" y="0.5" width="54" height="19" rx="2"/><rect x="60.5" y="0.5" width="29" height="19" rx="2" fill="#fafafa"/><rect x="60" y="7.5" width="0.5" height="5" stroke="#fafafa"/><path d="M60.5 6.5 l-3 3v1 l3 3" stroke="d5d5d5" fill="#fafafa"/></g><image x="5" y="3" width="14" height="14" xlink:href="data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMTgxNzE3IiByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dGl0bGU+R2l0SHViPC90aXRsZT48cGF0aCBkPSJNMTIgLjI5N2MtNi42MyAwLTEyIDUuMzczLTEyIDEyIDAgNS4zMDMgMy40MzggOS44IDguMjA1IDExLjM4NS42LjExMy44Mi0uMjU4LjgyLS41NzcgMC0uMjg1LS4wMS0xLjA0LS4wMTUtMi4wNC0zLjMzOC43MjQtNC4wNDItMS42MS00LjA0Mi0xLjYxQzQuNDIyIDE4LjA3IDMuNjMzIDE3LjcgMy42MzMgMTcuN2MtMS4wODctLjc0NC4wODQtLjcyOS4wODQtLjcyOSAxLjIwNS4wODQgMS44MzggMS4yMzYgMS44MzggMS4yMzYgMS4wNyAxLjgzNSAyLjgwOSAxLjMwNSAzLjQ5NS45OTguMTA4LS43NzYuNDE3LTEuMzA1Ljc2LTEuNjA1LTIuNjY1LS4zLTUuNDY2LTEuMzMyLTUuNDY2LTUuOTMgMC0xLjMxLjQ2NS0yLjM4IDEuMjM1LTMuMjItLjEzNS0uMzAzLS41NC0xLjUyMy4xMDUtMy4xNzYgMCAwIDEuMDA1LS4zMjIgMy4zIDEuMjMuOTYtLjI2NyAxLjk4LS4zOTkgMy0uNDA1IDEuMDIuMDA2IDIuMDQuMTM4IDMgLjQwNSAyLjI4LTEuNTUyIDMuMjg1LTEuMjMgMy4yODUtMS4yMy42NDUgMS42NTMuMjQgMi44NzMuMTIgMy4xNzYuNzY1Ljg0IDEuMjMgMS45MSAxLjIzIDMuMjIgMCA0LjYxLTIuODA1IDUuNjI1LTUuNDc1IDUuOTIuNDIuMzYuODEgMS4wOTYuODEgMi4yMiAwIDEuNjA2LS4wMTUgMi44OTYtLjAxNSAzLjI4NiAwIC4zMTUuMjEuNjkuODI1LjU3QzIwLjU2NSAyMi4wOTIgMjQgMTcuNTkyIDI0IDEyLjI5N2MwLTYuNjI3LTUuMzczLTEyLTEyLTEyIi8+PC9zdmc+"/><g aria-hidden="false" fill="#333" text-anchor="middle" font-family="Helvetica Neue,Helvetica,Arial,sans-serif" text-rendering="geometricPrecision" font-weight="700" font-size="110px" line-height="14px"><a target="_blank" xlink:href="https://github.com/PaddlePaddle/PaddleHub"><text aria-hidden="true" x="355" y="150" fill="#fff" transform="scale(.1)" textLength="270">Stars</text><text x="355" y="140" transform="scale(.1)" textLength="270">Stars</text><rect id="llink" stroke="#d5d5d5" fill="url(#a)" x=".5" y=".5" width="54" height="19" rx="2"/></a><a target="_blank" xlink:href="https://github.com/PaddlePaddle/PaddleHub/stargazers"><rect width="30" x="60" height="20" fill="rgba(0,0,0,0)"/><text aria-hidden="true" x="745" y="150" fill="#fff" transform="scale(.1)" textLength="210">8.4k</text><text id="rlink" x="745" y="140" transform="scale(.1)" textLength="210">8.4k</text></a></g></svg></p>
|
237 |
Besides, you can use free GPU resourses in <a href="https://aistudio.baidu.com/aistudio/projectdetail/4462918", style="text-decoration: underline;" target="_blank"> aistudio </a> to enjoy more cases, have fun.
|
238 |
</p>
|
239 |
</div>
|
|
|
240 |
|
241 |
"""
|
242 |
)
|
|
|
244 |
"""
|
245 |
在"探索无限"的风格模式下,画作的真实风格完全可以由你的prompt来决定。下面是一些参考案例:
|
246 |
|
|
|
247 |
In "Explore infinity" style mode, how the image looks like is totally up to your prompt. Below are some cases:
|
248 |
|
249 |
### 复古未来主义风格
|