Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Lmdeploy
Commits
081a6e89
Unverified
Commit
081a6e89
authored
Jun 30, 2023
by
AllentDan
Committed by
GitHub
Jun 30, 2023
Browse files
refactor webui (#29)
parent
cb8ac1b0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
51 deletions
+46
-51
README.md
README.md
+1
-1
README_zh-CN.md
README_zh-CN.md
+1
-1
llmdeploy/app.py
llmdeploy/app.py
+44
-27
llmdeploy/webui/__init__.py
llmdeploy/webui/__init__.py
+0
-0
llmdeploy/webui/strings.py
llmdeploy/webui/strings.py
+0
-6
llmdeploy/webui/styles.py
llmdeploy/webui/styles.py
+0
-16
No files found.
README.md
View file @
081a6e89
...
@@ -161,7 +161,7 @@ python3 llmdeploy/serve/client.py {server_ip_addresss}:33337 1
...
@@ -161,7 +161,7 @@ python3 llmdeploy/serve/client.py {server_ip_addresss}:33337 1
## Inference with Web UI
## Inference with Web UI
```
shell
```
shell
python3 llmdeploy/
webui/
app.py
{
server_ip_addresss
}
:33337 model_name
python3 llmdeploy/app.py
{
server_ip_addresss
}
:33337 model_name
```
```
## User Guide
## User Guide
...
...
README_zh-CN.md
View file @
081a6e89
...
@@ -149,7 +149,7 @@ python3 llmdeploy/serve/client.py {server_ip_addresss}:33337 1
...
@@ -149,7 +149,7 @@ python3 llmdeploy/serve/client.py {server_ip_addresss}:33337 1
## 使用浏览器推理
## 使用浏览器推理
```
shell
```
shell
python3 llmdeploy/
webui/
app.py
{
server_ip_addresss
}
:33337 model_name
python3 llmdeploy/app.py
{
server_ip_addresss
}
:33337 model_name
```
```
## 量化部署
## 量化部署
在 fp16 模式下,可以开启 kv_cache int8 量化,单卡可服务更多用户。
在 fp16 模式下,可以开启 kv_cache int8 量化,单卡可服务更多用户。
...
...
llmdeploy/
webui/
app.py
→
llmdeploy/app.py
View file @
081a6e89
#
flake8: noqa
#
Copyright (c) OpenMMLab. All rights reserved.
from
functools
import
partial
from
functools
import
partial
import
threading
import
threading
from
typing
import
Sequence
import
fire
import
fire
import
gradio
as
gr
import
gradio
as
gr
import
os
import
os
from
strings
import
ABSTRACT
,
TITLE
from
styles
import
PARENT_BLOCK_CSS
from
llmdeploy.serve.fastertransformer.chatbot
import
Chatbot
from
llmdeploy.serve.fastertransformer.chatbot
import
Chatbot
CSS
=
"""
#container {
width: 95%;
margin-left: auto;
margin-right: auto;
}
def
chat_stream
(
instruction
,
#chatbot {
state_chatbot
,
height: 500px;
llama_chatbot
,
overflow: auto;
}
.chat_wrap_space {
margin-left: 0.5em
}
"""
THEME
=
gr
.
themes
.
Soft
(
primary_hue
=
gr
.
themes
.
colors
.
blue
,
secondary_hue
=
gr
.
themes
.
colors
.
sky
,
font
=
[
gr
.
themes
.
GoogleFont
(
"Inconsolata"
),
"Arial"
,
"sans-serif"
])
def
chat_stream
(
instruction
:
str
,
state_chatbot
:
Sequence
,
llama_chatbot
:
Chatbot
,
model_name
:
str
=
None
):
model_name
:
str
=
None
):
bot_summarized_response
=
''
bot_summarized_response
=
''
model_type
=
'fastertransformer'
model_type
=
'fastertransformer'
...
@@ -37,12 +58,9 @@ def chat_stream(instruction,
...
@@ -37,12 +58,9 @@ def chat_stream(instruction,
yield
(
state_chatbot
,
state_chatbot
,
f
'
{
bot_summarized_response
}
'
.
strip
())
yield
(
state_chatbot
,
state_chatbot
,
f
'
{
bot_summarized_response
}
'
.
strip
())
def
reset_textbox
():
def
reset_all_func
(
instruction_txtbox
:
gr
.
Textbox
,
state_chatbot
:
gr
.
State
,
return
gr
.
Textbox
.
update
(
value
=
''
)
llama_chatbot
:
gr
.
State
,
triton_server_addr
:
str
,
model_name
:
str
):
def
reset_everything_func
(
instruction_txtbox
,
state_chatbot
,
llama_chatbot
,
triton_server_addr
,
model_name
):
state_chatbot
=
[]
state_chatbot
=
[]
log_level
=
os
.
environ
.
get
(
'SERVICE_LOG_LEVEL'
,
'INFO'
)
log_level
=
os
.
environ
.
get
(
'SERVICE_LOG_LEVEL'
,
'INFO'
)
...
@@ -57,7 +75,11 @@ def reset_everything_func(instruction_txtbox, state_chatbot, llama_chatbot,
...
@@ -57,7 +75,11 @@ def reset_everything_func(instruction_txtbox, state_chatbot, llama_chatbot,
)
)
def
cancel_func
(
instruction_txtbox
,
state_chatbot
,
llama_chatbot
):
def
cancel_func
(
instruction_txtbox
:
gr
.
Textbox
,
state_chatbot
:
gr
.
State
,
llama_chatbot
:
gr
.
State
,
):
session_id
=
llama_chatbot
.
_session
.
session_id
session_id
=
llama_chatbot
.
_session
.
session_id
llama_chatbot
.
cancel
(
session_id
)
llama_chatbot
.
cancel
(
session_id
)
...
@@ -71,10 +93,10 @@ def run(triton_server_addr: str,
...
@@ -71,10 +93,10 @@ def run(triton_server_addr: str,
model_name
:
str
,
model_name
:
str
,
server_name
:
str
=
'localhost'
,
server_name
:
str
=
'localhost'
,
server_port
:
int
=
6006
):
server_port
:
int
=
6006
):
with
gr
.
Blocks
(
css
=
PARENT_BLOCK_CSS
,
theme
=
'ParityError/Anime'
)
as
demo
:
with
gr
.
Blocks
(
css
=
CSS
,
theme
=
THEME
)
as
demo
:
chat_interface
=
partial
(
chat_stream
,
model_name
=
model_name
)
chat_interface
=
partial
(
chat_stream
,
model_name
=
model_name
)
reset_
everything
=
partial
(
reset_
all
=
partial
(
reset_
everything
_func
,
reset_
all
_func
,
model_name
=
model_name
,
model_name
=
model_name
,
triton_server_addr
=
triton_server_addr
)
triton_server_addr
=
triton_server_addr
)
log_level
=
os
.
environ
.
get
(
'SERVICE_LOG_LEVEL'
,
'INFO'
)
log_level
=
os
.
environ
.
get
(
'SERVICE_LOG_LEVEL'
,
'INFO'
)
...
@@ -86,16 +108,12 @@ def run(triton_server_addr: str,
...
@@ -86,16 +108,12 @@ def run(triton_server_addr: str,
display
=
True
))
display
=
True
))
state_chatbot
=
gr
.
State
([])
state_chatbot
=
gr
.
State
([])
with
gr
.
Column
(
elem_id
=
'col_container'
):
with
gr
.
Column
(
elem_id
=
'container'
):
gr
.
Markdown
(
f
'##
{
TITLE
}
\n\n\n
{
ABSTRACT
}
'
)
gr
.
Markdown
(
'## LLMDeploy Playground'
)
# with gr.Accordion('Context Setting', open=False):
# hidden_txtbox = gr.Textbox(
# placeholder='', label='Order', visible=False)
chatbot
=
gr
.
Chatbot
(
elem_id
=
'chatbot'
,
label
=
model_name
)
chatbot
=
gr
.
Chatbot
(
elem_id
=
'chatbot'
,
label
=
model_name
)
instruction_txtbox
=
gr
.
Textbox
(
instruction_txtbox
=
gr
.
Textbox
(
placeholder
=
'
What do you want to say to AI?
'
,
placeholder
=
'
Please input the instruction
'
,
label
=
'Instruction'
)
label
=
'Instruction'
)
with
gr
.
Row
():
with
gr
.
Row
():
cancel_btn
=
gr
.
Button
(
value
=
'Cancel'
)
cancel_btn
=
gr
.
Button
(
value
=
'Cancel'
)
...
@@ -108,8 +126,8 @@ def run(triton_server_addr: str,
...
@@ -108,8 +126,8 @@ def run(triton_server_addr: str,
batch
=
False
,
batch
=
False
,
max_batch_size
=
1
,
max_batch_size
=
1
,
)
)
reset_event
=
instruction_txtbox
.
submit
(
instruction_txtbox
.
submit
(
reset_textbox
,
lambda
:
gr
.
Textbox
.
update
(
value
=
''
)
,
[],
[],
[
instruction_txtbox
],
[
instruction_txtbox
],
)
)
...
@@ -120,8 +138,7 @@ def run(triton_server_addr: str,
...
@@ -120,8 +138,7 @@ def run(triton_server_addr: str,
cancels
=
[
send_event
])
cancels
=
[
send_event
])
reset_btn
.
click
(
reset_btn
.
click
(
reset_everything
,
reset_all
,
[
instruction_txtbox
,
state_chatbot
,
llama_chatbot
],
[
instruction_txtbox
,
state_chatbot
,
llama_chatbot
],
[
llama_chatbot
,
state_chatbot
,
chatbot
,
instruction_txtbox
],
[
llama_chatbot
,
state_chatbot
,
chatbot
,
instruction_txtbox
],
cancels
=
[
send_event
])
cancels
=
[
send_event
])
...
...
llmdeploy/webui/__init__.py
deleted
100644 → 0
View file @
cb8ac1b0
llmdeploy/webui/strings.py
deleted
100644 → 0
View file @
cb8ac1b0
# flake8: noqa
TITLE
=
'LLMDeploy Playground'
ABSTRACT
=
"""
Thanks to [LLM-As-Chatbot](https://github.com/deep-diver/LLM-As-Chatbot), this application was modified from it.
"""
llmdeploy/webui/styles.py
deleted
100644 → 0
View file @
cb8ac1b0
PARENT_BLOCK_CSS
=
"""
#col_container {
width: 95%;
margin-left: auto;
margin-right: auto;
}
#chatbot {
height: 500px;
overflow: auto;
}
.chat_wrap_space {
margin-left: 0.5em
}
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment