Spaces:
Sleeping
Sleeping
KevinNuNu
commited on
Commit
·
1187826
1
Parent(s):
7576ed5
test
Browse files
app.py
CHANGED
|
@@ -1,12 +1,69 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
from lmdeploy.serve.gradio.app import *
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
with gr.Blocks(css=CSS, theme=THEME) as demo:
|
| 6 |
state_chatbot = gr.State([])
|
| 7 |
|
| 8 |
with gr.Column(elem_id='container'):
|
| 9 |
gr.Markdown('## LMDeploy Playground')
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# print(f'server is gonna mount on: http://{server_name}:{server_port}')
|
| 12 |
-
demo.queue(concurrency_count=
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from lmdeploy.serve.gradio.app import *
|
| 3 |
|
| 4 |
+
async def chat_stream_test(
|
| 5 |
+
instruction: str,
|
| 6 |
+
state_chatbot: Sequence,
|
| 7 |
+
cancel_btn: gr.Button,
|
| 8 |
+
reset_btn: gr.Button,
|
| 9 |
+
request: gr.Request,
|
| 10 |
+
):
|
| 11 |
+
"""Chat with AI assistant.
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
instruction (str): user's prompt
|
| 15 |
+
state_chatbot (Sequence): the chatting history
|
| 16 |
+
request (gr.Request): the request from a user
|
| 17 |
+
"""
|
| 18 |
+
session_id = threading.current_thread().ident
|
| 19 |
+
if request is not None:
|
| 20 |
+
session_id = int(request.kwargs['client']['host'].replace('.', ''))
|
| 21 |
+
else:
|
| 22 |
+
print('Warning, could not get a request ip')
|
| 23 |
+
print(f'session_id {session_id}')
|
| 24 |
+
bot_summarized_response = ''
|
| 25 |
+
state_chatbot = state_chatbot + [(instruction, None)]
|
| 26 |
+
|
| 27 |
+
yield (state_chatbot, state_chatbot, disable_btn, enable_btn,
|
| 28 |
+
f'{bot_summarized_response}'.strip())
|
| 29 |
+
|
| 30 |
+
yield (state_chatbot, state_chatbot, disable_btn, enable_btn,
|
| 31 |
+
f'{bot_summarized_response}'.strip())
|
| 32 |
+
|
| 33 |
+
|
| 34 |
with gr.Blocks(css=CSS, theme=THEME) as demo:
|
| 35 |
state_chatbot = gr.State([])
|
| 36 |
|
| 37 |
with gr.Column(elem_id='container'):
|
| 38 |
gr.Markdown('## LMDeploy Playground')
|
| 39 |
|
| 40 |
+
chatbot = gr.Chatbot(
|
| 41 |
+
elem_id='chatbot',
|
| 42 |
+
label="test")
|
| 43 |
+
instruction_txtbox = gr.Textbox(
|
| 44 |
+
placeholder='Please input the instruction',
|
| 45 |
+
label='Instruction')
|
| 46 |
+
with gr.Row():
|
| 47 |
+
cancel_btn = gr.Button(value='Cancel', interactive=False)
|
| 48 |
+
reset_btn = gr.Button(value='Reset')
|
| 49 |
+
|
| 50 |
+
send_event = instruction_txtbox.submit(
|
| 51 |
+
chat_stream_test,
|
| 52 |
+
[instruction_txtbox, state_chatbot, cancel_btn, reset_btn],
|
| 53 |
+
[state_chatbot, chatbot, cancel_btn, reset_btn])
|
| 54 |
+
instruction_txtbox.submit(
|
| 55 |
+
lambda: gr.Textbox.update(value=''),
|
| 56 |
+
[],
|
| 57 |
+
[instruction_txtbox],
|
| 58 |
+
)
|
| 59 |
+
cancel_btn.click(cancel_local_func,
|
| 60 |
+
[state_chatbot, cancel_btn, reset_btn],
|
| 61 |
+
[state_chatbot, cancel_btn, reset_btn],
|
| 62 |
+
cancels=[send_event])
|
| 63 |
+
|
| 64 |
+
reset_btn.click(reset_local_func, [instruction_txtbox, state_chatbot],
|
| 65 |
+
[state_chatbot, chatbot, instruction_txtbox],
|
| 66 |
+
cancels=[send_event])
|
| 67 |
+
|
| 68 |
# print(f'server is gonna mount on: http://{server_name}:{server_port}')
|
| 69 |
+
demo.queue(concurrency_count=4, max_size=100).launch()
|