Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ from dashscope import Generation
|
|
7 |
from dashscope.api_entities.dashscope_response import Role
|
8 |
from typing import List, Optional, Tuple, Dict
|
9 |
from urllib.error import HTTPError
|
10 |
-
|
11 |
default_system = 'You are a helpful assistant.'
|
12 |
|
13 |
YOUR_API_TOKEN = os.getenv('YOUR_API_TOKEN')
|
@@ -31,6 +30,7 @@ def history_to_messages(history: History, system: str) -> Messages:
|
|
31 |
messages.append({'role': Role.ASSISTANT, 'content': h[1]})
|
32 |
return messages
|
33 |
|
|
|
34 |
def messages_to_history(messages: Messages) -> Tuple[str, History]:
|
35 |
assert messages[0]['role'] == Role.SYSTEM
|
36 |
system = messages[0]['content']
|
@@ -39,7 +39,9 @@ def messages_to_history(messages: Messages) -> Tuple[str, History]:
|
|
39 |
history.append([q['content'], r['content']])
|
40 |
return system, history
|
41 |
|
42 |
-
|
|
|
|
|
43 |
if query is None:
|
44 |
query = ''
|
45 |
if history is None:
|
@@ -64,48 +66,40 @@ def model_chat(query: Optional[str], history: Optional[History], system: str) ->
|
|
64 |
response.code, response.message
|
65 |
))
|
66 |
|
|
|
67 |
with gr.Blocks() as demo:
|
68 |
gr.Markdown("""<center><font size=8>Qwen2.5-Max👾</center>""")
|
69 |
|
70 |
with gr.Row():
|
71 |
with gr.Column(scale=3):
|
72 |
-
system_input = gr.Textbox(value=default_system, lines=
|
73 |
with gr.Column(scale=1):
|
74 |
-
modify_system = gr.Button("🛠️ Set
|
75 |
system_state = gr.Textbox(value=default_system, visible=False)
|
76 |
-
|
77 |
-
|
78 |
-
textbox = gr.Textbox(lines=2, label='Your Message', placeholder="Type your message here...")
|
79 |
|
80 |
with gr.Row():
|
81 |
-
clear_history = gr.Button("🧹 Clear
|
82 |
-
|
83 |
-
|
84 |
-
with gr.Accordion("Advanced Settings", open=False):
|
85 |
-
with gr.Row():
|
86 |
-
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Temperature")
|
87 |
-
max_tokens = gr.Slider(minimum=50, maximum=500, value=150, label="Max Tokens")
|
88 |
-
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, label="Top-p")
|
89 |
|
90 |
textbox.submit(model_chat,
|
91 |
-
inputs=[textbox, chatbot, system_state],
|
92 |
-
outputs=[textbox, chatbot, system_input],
|
93 |
-
concurrency_limit=40)
|
94 |
-
|
95 |
-
submit.click(model_chat,
|
96 |
inputs=[textbox, chatbot, system_state],
|
97 |
outputs=[textbox, chatbot, system_input],
|
98 |
-
concurrency_limit=40)
|
99 |
|
|
|
|
|
|
|
|
|
100 |
clear_history.click(fn=clear_session,
|
101 |
inputs=[],
|
102 |
outputs=[textbox, chatbot],
|
103 |
-
concurrency_limit=40)
|
104 |
-
|
105 |
modify_system.click(fn=modify_system_session,
|
106 |
inputs=[system_input],
|
107 |
outputs=[system_state, system_input, chatbot],
|
108 |
-
concurrency_limit=40)
|
109 |
|
110 |
demo.queue(api_open=False)
|
111 |
-
demo.launch(max_threads=40)
|
|
|
7 |
from dashscope.api_entities.dashscope_response import Role
|
8 |
from typing import List, Optional, Tuple, Dict
|
9 |
from urllib.error import HTTPError
|
|
|
10 |
default_system = 'You are a helpful assistant.'
|
11 |
|
12 |
YOUR_API_TOKEN = os.getenv('YOUR_API_TOKEN')
|
|
|
30 |
messages.append({'role': Role.ASSISTANT, 'content': h[1]})
|
31 |
return messages
|
32 |
|
33 |
+
|
34 |
def messages_to_history(messages: Messages) -> Tuple[str, History]:
|
35 |
assert messages[0]['role'] == Role.SYSTEM
|
36 |
system = messages[0]['content']
|
|
|
39 |
history.append([q['content'], r['content']])
|
40 |
return system, history
|
41 |
|
42 |
+
|
43 |
+
def model_chat(query: Optional[str], history: Optional[History], system: str
|
44 |
+
) -> Tuple[str, str, History]:
|
45 |
if query is None:
|
46 |
query = ''
|
47 |
if history is None:
|
|
|
66 |
response.code, response.message
|
67 |
))
|
68 |
|
69 |
+
|
70 |
with gr.Blocks() as demo:
|
71 |
gr.Markdown("""<center><font size=8>Qwen2.5-Max👾</center>""")
|
72 |
|
73 |
with gr.Row():
|
74 |
with gr.Column(scale=3):
|
75 |
+
system_input = gr.Textbox(value=default_system, lines=1, label='System')
|
76 |
with gr.Column(scale=1):
|
77 |
+
modify_system = gr.Button("🛠️ Set system prompt and clear history", scale=2)
|
78 |
system_state = gr.Textbox(value=default_system, visible=False)
|
79 |
+
chatbot = gr.Chatbot(label='qwen2.5-max')
|
80 |
+
textbox = gr.Textbox(lines=1, label='Input')
|
|
|
81 |
|
82 |
with gr.Row():
|
83 |
+
clear_history = gr.Button("🧹 Clear history")
|
84 |
+
sumbit = gr.Button("🚀 Send")
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
textbox.submit(model_chat,
|
|
|
|
|
|
|
|
|
|
|
87 |
inputs=[textbox, chatbot, system_state],
|
88 |
outputs=[textbox, chatbot, system_input],
|
89 |
+
concurrency_limit = 40)
|
90 |
|
91 |
+
sumbit.click(model_chat,
|
92 |
+
inputs=[textbox, chatbot, system_state],
|
93 |
+
outputs=[textbox, chatbot, system_input],
|
94 |
+
concurrency_limit = 40)
|
95 |
clear_history.click(fn=clear_session,
|
96 |
inputs=[],
|
97 |
outputs=[textbox, chatbot],
|
98 |
+
concurrency_limit = 40)
|
|
|
99 |
modify_system.click(fn=modify_system_session,
|
100 |
inputs=[system_input],
|
101 |
outputs=[system_state, system_input, chatbot],
|
102 |
+
concurrency_limit = 40)
|
103 |
|
104 |
demo.queue(api_open=False)
|
105 |
+
demo.launch(max_threads=40)
|