Skip to content

Commit 4978959

Browse files
update visualQnA chinese version (#354)
* update visualQnA chinese version Signed-off-by: WenjiaoYue <wenjiao.yue@intel.com> --------- Signed-off-by: WenjiaoYue <wenjiao.yue@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ff05573 commit 4978959

2 files changed

Lines changed: 123 additions & 4 deletions

File tree

VisualQnA/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,29 @@ If the reply has a `200 OK`, then the service is up.
5050

5151
## Start the Gradio app
5252

53-
Now you can start the frontend UI by following commands:
53+
Now you have two options to start the frontend UI by following commands:
54+
55+
### English Interface (Default)
5456

5557
```
5658
cd ui/
5759
pip install -r requirements.txt
5860
http_proxy= python app.py --host 0.0.0.0 --port 7860 --worker-addr http://localhost:8085 --share
5961
```
6062

63+
### Chinese Interface
64+
65+
```
66+
cd ui/
67+
pip install -r requirements.txt
68+
http_proxy= python app.py --host 0.0.0.0 --port 7860 --worker-addr http://localhost:8085 --lang CN --share
69+
```
70+
6171
Here are some explanation about the above parameters:
6272

6373
- `--host`: the host of the gradio app
6474
- `--port`: the port of the gradio app, by default 7860
6575
- `--worker-addr`: the LLaVA service IP address. If you setup the service on a different machine, please replace `localhost` to the IP address of your Gaudi2 host machine
66-
67-
#
76+
- `--lang`: Specify this parameter to use the Chinese interface. The default UI language is English and can be used without any additional parameter.
6877

6978
SCRIPT USAGE NOTICE:  By downloading and using any script file included with the associated software package (such as files with .bat, .cmd, or .JS extensions, Docker files, or any other type of file that, when executed, automatically downloads and/or installs files onto your system) (the “Script File”), it is your obligation to review the Script File to understand what files (e.g.,  other software, AI models, AI Datasets) the Script File will download to your system (“Downloaded Files”). Furthermore, by downloading and using the Downloaded Files, even if they are installed through a silent install, you agree to any and all terms and conditions associated with such files, including but not limited to, license terms, notices, or disclaimers.

VisualQnA/ui/gradio/app.py

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,37 @@
2424
For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
2525
"""
2626

27+
title_markdown_cn = """
28+
# 🌋 在 Gaudi2 上展示 LLaVA
29+
"""
30+
31+
tos_markdown_cn = """
32+
### 使用条款
33+
使用本服务即表示用户同意以下条款:
34+
本服务为研究预览版,仅供非商业用途。它仅提供有限的安全措施,可能会生成冒犯性内容。严禁将本服务用于任何非法、有害、暴力、种族歧视或色情的目的。本服务可能会收集用户对话数据以用于未来研究。
35+
为获得最佳体验,请使用台式电脑访问本演示,因为移动设备可能会影响其质量。
36+
"""
37+
2738
block_css = """
2839
2940
#buttons button {
3041
min-width: min(120px,100%);
3142
}
3243
44+
.upload-container .wrap,
45+
.upload-container .wrap .or {
46+
color: #1f2937;
47+
}
48+
49+
50+
.upload-container .wrap .icon-wrap {
51+
color: #e5e7eb;
52+
margin-top: 4rem;
53+
width: 4rem;
54+
height: 3rem;
55+
}
56+
57+
3358
"""
3459

3560
no_change_btn = gr.Button()
@@ -84,6 +109,85 @@ def clear_history(chat_history, image, text):
84109
return [chat_history, image, text] + [disable_btn]
85110

86111

112+
def build_demo_cn(embed_mode, cur_dir=None, concurrency_count=10):
113+
textbox = gr.Textbox(show_label=False, placeholder="输入文字并按回车键", container=False)
114+
with gr.Blocks(title="LLaVA", theme=gr.themes.Default(), css=block_css) as demo:
115+
# demo.add(custom_html)
116+
117+
state = gr.State()
118+
119+
if not embed_mode:
120+
gr.Markdown(title_markdown_cn)
121+
122+
with gr.Row():
123+
with gr.Column(scale=3):
124+
imagebox = gr.Image(type="pil", label="图片", interactive=True, elem_id="my_imagebox")
125+
126+
if cur_dir is None:
127+
cur_dir = os.path.dirname(os.path.abspath(__file__))
128+
gr.Examples(
129+
examples=[
130+
[f"{cur_dir}/resources/extreme_ironing.jpg", "这张图片有什么不寻常之处?"],
131+
[
132+
f"{cur_dir}/resources/waterview.jpg",
133+
"当我去那里访问时,我应该注意哪些事情?",
134+
],
135+
],
136+
label="请选择一个示例",
137+
inputs=[imagebox, textbox],
138+
)
139+
140+
with gr.Accordion("参数", open=False) as parameter_row:
141+
max_output_tokens = gr.Slider(
142+
minimum=0,
143+
maximum=1024,
144+
value=512,
145+
step=64,
146+
interactive=True,
147+
label="最大输出标记数",
148+
)
149+
150+
with gr.Column(scale=8):
151+
chatbot = gr.Chatbot(
152+
elem_id="chatbot",
153+
label="LLaVA聊天机器人",
154+
height=650,
155+
layout="panel",
156+
)
157+
with gr.Row():
158+
with gr.Column(scale=8):
159+
textbox.render()
160+
with gr.Column(scale=1, min_width=50):
161+
submit_btn = gr.Button(value="发送", variant="primary")
162+
with gr.Row(elem_id="buttons") as button_row:
163+
clear_btn = gr.Button(value="🗑️ 清除", interactive=False)
164+
165+
if not embed_mode:
166+
gr.Markdown(tos_markdown_cn)
167+
168+
btn_list = [clear_btn]
169+
170+
clear_btn.click(
171+
clear_history,
172+
[chatbot, imagebox, textbox],
173+
[chatbot, imagebox, textbox] + btn_list,
174+
)
175+
176+
textbox.submit(
177+
handle_llava_request,
178+
[textbox, imagebox, max_output_tokens, chatbot],
179+
[chatbot] + btn_list,
180+
)
181+
182+
submit_btn.click(
183+
handle_llava_request,
184+
[textbox, imagebox, max_output_tokens, chatbot],
185+
[chatbot] + btn_list,
186+
)
187+
188+
return demo
189+
190+
87191
def build_demo(embed_mode, cur_dir=None, concurrency_count=10):
88192
textbox = gr.Textbox(show_label=False, placeholder="Enter text and press ENTER", container=False)
89193
with gr.Blocks(title="LLaVA", theme=gr.themes.Default(), css=block_css) as demo:
@@ -165,6 +269,8 @@ def build_demo(embed_mode, cur_dir=None, concurrency_count=10):
165269
# frontend host and port
166270
parser.add_argument("--host", type=str, default="0.0.0.0")
167271
parser.add_argument("--port", type=int)
272+
parser.add_argument("--lang", type=str, default="En")
273+
168274
# backend worker address
169275
parser.add_argument(
170276
"--worker-addr", type=str, default="http://localhost:8085", help="The worker address of the LLaVA server."
@@ -175,6 +281,10 @@ def build_demo(embed_mode, cur_dir=None, concurrency_count=10):
175281

176282
args = parser.parse_args()
177283
print(args)
178-
demo = build_demo(args.embed, concurrency_count=args.concurrency_count)
284+
selectedLang = args.lang
285+
if selectedLang == "CN":
286+
demo = build_demo_cn(args.embed, concurrency_count=args.concurrency_count)
287+
else:
288+
demo = build_demo(args.embed, concurrency_count=args.concurrency_count)
179289

180290
demo.queue(api_open=False).launch(server_name=args.host, server_port=args.port, share=args.share)

0 commit comments

Comments
 (0)