MotZepka commited on
Commit
adcc0d4
·
verified ·
1 Parent(s): 083c95d

Update web_ui.py

Browse files
Files changed (1) hide show
  1. web_ui.py +104 -117
web_ui.py CHANGED
@@ -66,133 +66,120 @@ class WebUI:
66
  messages: The chat history.
67
  """
68
 
69
- def run(self,
70
- messages: List[Message] = None,
71
- share: bool = False,
72
- server_name: str = None,
73
- server_port: int = None,
74
- concurrency_limit: int = 10,
75
- enable_mention: bool = False,
76
- **kwargs):
77
- self.run_kwargs = kwargs
78
-
79
- from qwen_agent.gui.gradio import gr, mgr
80
-
81
- customTheme = gr.themes.Default(
82
- primary_hue=gr.themes.utils.colors.blue,
83
- radius_size=gr.themes.utils.sizes.radius_none,
84
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- with gr.Blocks(
87
- css=os.path.join(os.path.dirname(__file__), 'assets/appBot.css'),
88
- theme=customTheme,
89
- ) as demo:
90
- history = gr.State([])
91
-
92
- with gr.Row(elem_classes='container'):
93
- with gr.Column(scale=4):
94
- chatbot = mgr.Chatbot(value=convert_history_to_chatbot(messages=messages),
95
- avatar_images=[
96
- self.user_config,
97
- self.agent_config_list,
98
- ],
99
- height=650,
100
- avatar_image_width=80,
101
- flushing=False,
102
- show_copy_button=True,
103
- latex_delimiters=[{
104
- 'left': '\\(',
105
- 'right': '\\)',
106
- 'display': True
107
- }, {
108
- 'left': '\\begin{equation}',
109
- 'right': '\\end{equation}',
110
- 'display': True
111
- }, {
112
- 'left': '\\begin{align}',
113
- 'right': '\\end{align}',
114
- 'display': True
115
- }, {
116
- 'left': '\\begin{alignat}',
117
- 'right': '\\end{alignat}',
118
- 'display': True
119
- }, {
120
- 'left': '\\begin{gather}',
121
- 'right': '\\end{gather}',
122
- 'display': True
123
- }, {
124
- 'left': '\\begin{CD}',
125
- 'right': '\\end{CD}',
126
- 'display': True
127
- }, {
128
- 'left': '\\[',
129
- 'right': '\\]',
130
- 'display': True
131
- }])
132
-
133
- input = mgr.MultimodalInput(placeholder=self.input_placeholder, upload_button_props=dict(file_types=[".pdf", ".docx", ".pptx", ".txt", ".html", ".csv", ".tsv", ".xlsx", ".xls"] + ["." + file_type for file_type in common_programming_language_extensions]))
134
-
135
- with gr.Column(scale=1):
136
- if len(self.agent_list) > 1:
137
- agent_selector = gr.Dropdown(
138
- [(agent.name, i) for i, agent in enumerate(self.agent_list)],
139
- label='Agents',
140
- info='选择一个Agent',
141
- value=0,
142
- interactive=True,
143
  )
144
-
145
- agent_info_block = self._create_agent_info_block()
146
-
147
- # agent_plugins_block = self._create_agent_plugins_block()
148
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  if self.prompt_suggestions:
150
  gr.Examples(
151
- label='推荐对话',
152
  examples=self.prompt_suggestions,
153
  inputs=[input],
154
  )
155
 
156
- if len(self.agent_list) > 1:
157
- agent_selector.change(
158
- fn=self.change_agent,
159
- inputs=[agent_selector],
160
- outputs=[agent_selector, agent_info_block, agent_plugins_block],
161
- queue=False,
162
- )
163
-
164
- input_promise = input.submit(
165
- fn=self.add_text,
166
- inputs=[input, chatbot, history],
167
- outputs=[input, chatbot, history],
168
- queue=False,
169
- )
170
-
171
- if len(self.agent_list) > 1 and enable_mention:
172
- input_promise = input_promise.then(
173
- self.add_mention,
174
- [chatbot, agent_selector],
175
- [chatbot, agent_selector],
176
- ).then(
177
- self.agent_run,
178
- [chatbot, history, agent_selector],
179
- [chatbot, history, agent_selector],
180
- )
181
- else:
182
- input_promise = input_promise.then(
183
- self.agent_run,
184
- [chatbot, history],
185
- [chatbot, history],
186
- )
187
-
188
- input_promise.then(self.flushed, None, [input])
189
-
190
- demo.load(None)
191
 
192
- demo.queue(default_concurrency_limit=concurrency_limit).launch(share=share,
193
- server_name=server_name,
194
- server_port=server_port)
 
 
 
 
 
 
 
195
 
 
 
 
 
 
 
196
  def change_agent(self, agent_selector):
197
  yield agent_selector, self._create_agent_info_block(agent_selector), self._create_agent_plugins_block(
198
  agent_selector)
 
66
  messages: The chat history.
67
  """
68
 
69
+ def run(self,
70
+ messages: List[Message] = None,
71
+ share: bool = False,
72
+ server_name: str = None,
73
+ server_port: int = None,
74
+ concurrency_limit: int = 10,
75
+ enable_mention: bool = False,
76
+ **kwargs):
77
+ self.run_kwargs = kwargs
78
+
79
+ from qwen_agent.gui.gradio import gr, mgr
80
+
81
+ # Создаем более современную цветовую схему
82
+ customTheme = gr.themes.Soft(
83
+ primary_hue=gr.themes.colors.blue,
84
+ secondary_hue=gr.themes.colors.gray,
85
+ radius_size=gr.themes.sizes.radius_md,
86
+ )
87
+
88
+ with gr.Blocks(
89
+ css=os.path.join(os.path.dirname(__file__), 'assets/appBot.css'),
90
+ theme=customTheme,
91
+ ) as demo:
92
+ history = gr.State([])
93
+
94
+ with gr.Container():
95
+ with gr.Row():
96
+ with gr.Column(scale=3):
97
+ # Улучшенный чатбот с расширенными опциями
98
+ chatbot = mgr.Chatbot(
99
+ value=convert_history_to_chatbot(messages=messages),
100
+ avatar_images=[
101
+ self.user_config,
102
+ self.agent_config_list,
103
+ ],
104
+ height=700,
105
+ avatar_image_width=60,
106
+ bubble_full_width=False,
107
+ layout='bubble',
108
+ show_copy_button=True,
109
+ show_share_button=True,
110
+ latex_delimiters=[
111
+ {'left': '\\(', 'right': '\\)', 'display': False},
112
+ {'left': '\\[', 'right': '\\]', 'display': True},
113
+ ]
114
+ )
115
 
116
+ # Улучшенный мультимодальный ввод
117
+ with gr.Row():
118
+ input = mgr.MultimodalInput(
119
+ placeholder=self.input_placeholder,
120
+ upload_button_props=dict(
121
+ file_types=[
122
+ ".pdf", ".docx", ".pptx", ".txt",
123
+ ".html", ".csv", ".tsv", ".xlsx", ".xls"
124
+ ] + ["." + file_type for file_type in common_programming_language_extensions]
125
+ ),
126
+ show_label=False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  )
128
+ send_btn = gr.Button("Отправить", variant="primary", size="lg")
129
+
130
+ with gr.Column(scale=1, min_width=300):
131
+ # Боковая панель с информацией об агенте
132
+ with gr.Card(variant="filled"):
133
+ agent_info_block = self._create_agent_info_block()
134
+
135
+ # Селектор агентов (если их несколько)
136
+ if len(self.agent_list) > 1:
137
+ agent_selector = gr.Dropdown(
138
+ [(agent.name, i) for i, agent in enumerate(self.agent_list)],
139
+ label='Выберите агента',
140
+ value=0,
141
+ interactive=True,
142
+ )
143
+
144
+ # Блок с возможностями агента
145
+ agent_plugins_block = self._create_agent_plugins_block()
146
+
147
+ # Рекомендованные промпты
148
  if self.prompt_suggestions:
149
  gr.Examples(
150
+ label='Быстрый старт',
151
  examples=self.prompt_suggestions,
152
  inputs=[input],
153
  )
154
 
155
+ # Привязка событий
156
+ send_btn.click(
157
+ fn=self.add_text,
158
+ inputs=[input, chatbot, history],
159
+ outputs=[input, chatbot, history]
160
+ ).then(
161
+ self.agent_run,
162
+ [chatbot, history],
163
+ [chatbot, history]
164
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
+ # Обработка ввода по нажатию Enter
167
+ input.submit(
168
+ fn=self.add_text,
169
+ inputs=[input, chatbot, history],
170
+ outputs=[input, chatbot, history]
171
+ ).then(
172
+ self.agent_run,
173
+ [chatbot, history],
174
+ [chatbot, history]
175
+ )
176
 
177
+ # Запуск демо
178
+ demo.queue(default_concurrency_limit=concurrency_limit).launch(
179
+ share=share,
180
+ server_name=server_name,
181
+ server_port=server_port
182
+ )
183
  def change_agent(self, agent_selector):
184
  yield agent_selector, self._create_agent_info_block(agent_selector), self._create_agent_plugins_block(
185
  agent_selector)