Spaces:
Runtime error
Runtime error
Cascade Bot
commited on
Commit
Β·
5901371
1
Parent(s):
332e0c7
feat: enhance Gradio interface styling and UX
Browse files- Added modern theme with proper spacing and colors
- Added custom CSS for better chat styling
- Enhanced header with emojis and formatting
- Improved chat window layout and responsiveness
- Added loading states and dynamic button states
- Improved message formatting for code blocks
- Added emojis to buttons and example queries
app.py
CHANGED
@@ -191,36 +191,67 @@ class ChatInterface:
|
|
191 |
"""Get available venture types."""
|
192 |
return VentureAPI(self.reasoning_engine).get_venture_types()
|
193 |
|
194 |
-
def create_interface(self):
|
195 |
"""Create the Gradio interface."""
|
196 |
with gr.Blocks(
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
) as interface:
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
216 |
""")
|
217 |
|
218 |
chatbot = gr.Chatbot(
|
219 |
label="Chat History",
|
220 |
-
height=
|
221 |
bubble_full_width=False,
|
222 |
show_copy_button=True,
|
223 |
-
render_markdown=True
|
|
|
|
|
224 |
)
|
225 |
|
226 |
with gr.Row():
|
@@ -228,39 +259,44 @@ class ChatInterface:
|
|
228 |
label="Message",
|
229 |
placeholder="Chat with the Agentic System...",
|
230 |
lines=2,
|
231 |
-
|
232 |
-
|
233 |
-
container=
|
|
|
234 |
)
|
235 |
submit = gr.Button(
|
236 |
-
"Send",
|
237 |
scale=1,
|
238 |
variant="primary"
|
239 |
)
|
240 |
|
241 |
-
with gr.Row():
|
242 |
clear = gr.ClearButton(
|
243 |
[msg, chatbot],
|
244 |
-
value="Clear Chat",
|
245 |
variant="secondary",
|
246 |
scale=1
|
247 |
)
|
248 |
retry = gr.Button(
|
249 |
-
"Retry Last",
|
250 |
variant="secondary",
|
251 |
scale=1
|
252 |
)
|
253 |
|
254 |
async def respond(message, history):
|
|
|
255 |
try:
|
256 |
# Convert history to the format expected by process_message
|
257 |
history_list = [[x, y] for x, y in history] if history else []
|
258 |
response = await self.process_message(message, history_list)
|
259 |
|
|
|
|
|
|
|
260 |
# Update history
|
261 |
if history is None:
|
262 |
history = []
|
263 |
-
history.append((message,
|
264 |
|
265 |
return "", history
|
266 |
except Exception as e:
|
@@ -274,56 +310,66 @@ class ChatInterface:
|
|
274 |
return "", history
|
275 |
|
276 |
async def retry_last(history):
|
|
|
277 |
if not history:
|
278 |
return history
|
279 |
last_user_msg = history[-1][0]
|
280 |
history = history[:-1] # Remove last exchange
|
281 |
return await respond(last_user_msg, history)
|
282 |
|
283 |
-
# Submit handlers
|
284 |
-
msg.submit(
|
285 |
-
respond,
|
286 |
-
[msg, chatbot],
|
287 |
-
[msg, chatbot]
|
|
|
288 |
).then(
|
289 |
lambda: (gr.update(value="", interactive=True), gr.update(interactive=True)),
|
290 |
None,
|
291 |
[msg, submit]
|
292 |
)
|
293 |
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
[msg, chatbot]
|
|
|
|
|
298 |
).then(
|
299 |
lambda: (gr.update(value="", interactive=True), gr.update(interactive=True)),
|
300 |
None,
|
301 |
[msg, submit]
|
302 |
)
|
303 |
|
|
|
304 |
retry.click(
|
305 |
-
retry_last,
|
306 |
-
[chatbot],
|
307 |
-
[chatbot]
|
|
|
308 |
)
|
309 |
|
310 |
-
#
|
311 |
msg.change(
|
312 |
-
lambda x: (
|
|
|
|
|
|
|
313 |
[msg],
|
314 |
[msg, submit]
|
315 |
)
|
316 |
|
317 |
-
#
|
318 |
gr.Examples(
|
319 |
examples=[
|
320 |
-
"
|
321 |
-
"Create a new objective: Analyze market trends",
|
322 |
-
"
|
323 |
-
"
|
324 |
],
|
325 |
inputs=msg,
|
326 |
-
label="Example Queries"
|
|
|
327 |
)
|
328 |
|
329 |
return interface
|
|
|
191 |
"""Get available venture types."""
|
192 |
return VentureAPI(self.reasoning_engine).get_venture_types()
|
193 |
|
194 |
+
def create_interface(self) -> gr.Blocks:
|
195 |
"""Create the Gradio interface."""
|
196 |
with gr.Blocks(
|
197 |
+
title="Advanced Agentic System",
|
198 |
+
theme=gr.themes.Soft(
|
199 |
+
primary_hue="blue",
|
200 |
+
secondary_hue="slate",
|
201 |
+
neutral_hue="slate",
|
202 |
+
spacing_size=gr.themes.sizes.spacing_md,
|
203 |
+
radius_size=gr.themes.sizes.radius_md,
|
204 |
+
text_size=gr.themes.sizes.text_md,
|
205 |
+
),
|
206 |
+
css="""
|
207 |
+
.gradio-container {
|
208 |
+
max-width: 1200px !important;
|
209 |
+
margin: auto;
|
210 |
+
padding: 20px;
|
211 |
+
}
|
212 |
+
.chat-message {
|
213 |
+
padding: 15px;
|
214 |
+
border-radius: 10px;
|
215 |
+
margin-bottom: 10px;
|
216 |
+
}
|
217 |
+
.user-message {
|
218 |
+
background-color: #f0f0f0;
|
219 |
+
}
|
220 |
+
.assistant-message {
|
221 |
+
background-color: #e3f2fd;
|
222 |
+
}
|
223 |
+
footer {display: none !important;}
|
224 |
+
.gradio-container {min-height: 100vh !important;}
|
225 |
+
.main {flex-grow: 1;}
|
226 |
+
"""
|
227 |
) as interface:
|
228 |
+
gr.Markdown("""
|
229 |
+
# π€ Advanced Agentic System Chat Interface
|
230 |
+
|
231 |
+
Welcome to our AI-powered autonomous agent teams! Each team specializes in different domains:
|
232 |
+
|
233 |
+
- π» **Team A: Coders** - Expert software developers and architects
|
234 |
+
- πΌ **Team B: Business** - Strategic entrepreneurs and analysts
|
235 |
+
- π **Team C: Research** - Deep online research specialists
|
236 |
+
- π **Team D: Trading** - Crypto & sports trading experts
|
237 |
+
|
238 |
+
You can:
|
239 |
+
1. Ask questions about any domain
|
240 |
+
2. Create new objectives for teams
|
241 |
+
3. Check status of ongoing work
|
242 |
+
4. Get insights and recommendations
|
243 |
+
|
244 |
+
---
|
245 |
""")
|
246 |
|
247 |
chatbot = gr.Chatbot(
|
248 |
label="Chat History",
|
249 |
+
height=500,
|
250 |
bubble_full_width=False,
|
251 |
show_copy_button=True,
|
252 |
+
render_markdown=True,
|
253 |
+
container=True,
|
254 |
+
elem_classes=["chat-window"]
|
255 |
)
|
256 |
|
257 |
with gr.Row():
|
|
|
259 |
label="Message",
|
260 |
placeholder="Chat with the Agentic System...",
|
261 |
lines=2,
|
262 |
+
max_lines=10,
|
263 |
+
show_label=False,
|
264 |
+
container=False,
|
265 |
+
scale=9
|
266 |
)
|
267 |
submit = gr.Button(
|
268 |
+
"Send π",
|
269 |
scale=1,
|
270 |
variant="primary"
|
271 |
)
|
272 |
|
273 |
+
with gr.Row(equal_height=True):
|
274 |
clear = gr.ClearButton(
|
275 |
[msg, chatbot],
|
276 |
+
value="Clear Chat ποΈ",
|
277 |
variant="secondary",
|
278 |
scale=1
|
279 |
)
|
280 |
retry = gr.Button(
|
281 |
+
"Retry Last π",
|
282 |
variant="secondary",
|
283 |
scale=1
|
284 |
)
|
285 |
|
286 |
async def respond(message, history):
|
287 |
+
"""Handle chat responses with proper formatting."""
|
288 |
try:
|
289 |
# Convert history to the format expected by process_message
|
290 |
history_list = [[x, y] for x, y in history] if history else []
|
291 |
response = await self.process_message(message, history_list)
|
292 |
|
293 |
+
# Format response for markdown rendering
|
294 |
+
formatted_response = response.replace('```', '\n```\n')
|
295 |
+
|
296 |
# Update history
|
297 |
if history is None:
|
298 |
history = []
|
299 |
+
history.append((message, formatted_response))
|
300 |
|
301 |
return "", history
|
302 |
except Exception as e:
|
|
|
310 |
return "", history
|
311 |
|
312 |
async def retry_last(history):
|
313 |
+
"""Retry the last message with proper formatting."""
|
314 |
if not history:
|
315 |
return history
|
316 |
last_user_msg = history[-1][0]
|
317 |
history = history[:-1] # Remove last exchange
|
318 |
return await respond(last_user_msg, history)
|
319 |
|
320 |
+
# Submit handlers with loading states
|
321 |
+
submit_event = msg.submit(
|
322 |
+
fn=respond,
|
323 |
+
inputs=[msg, chatbot],
|
324 |
+
outputs=[msg, chatbot],
|
325 |
+
api_name=False
|
326 |
).then(
|
327 |
lambda: (gr.update(value="", interactive=True), gr.update(interactive=True)),
|
328 |
None,
|
329 |
[msg, submit]
|
330 |
)
|
331 |
|
332 |
+
# Click handlers with loading states
|
333 |
+
click_event = submit.click(
|
334 |
+
fn=respond,
|
335 |
+
inputs=[msg, chatbot],
|
336 |
+
outputs=[msg, chatbot],
|
337 |
+
api_name=False
|
338 |
).then(
|
339 |
lambda: (gr.update(value="", interactive=True), gr.update(interactive=True)),
|
340 |
None,
|
341 |
[msg, submit]
|
342 |
)
|
343 |
|
344 |
+
# Retry handler
|
345 |
retry.click(
|
346 |
+
fn=retry_last,
|
347 |
+
inputs=[chatbot],
|
348 |
+
outputs=[chatbot],
|
349 |
+
api_name=False
|
350 |
)
|
351 |
|
352 |
+
# Auto-focus and dynamic submit button state
|
353 |
msg.change(
|
354 |
+
lambda x: (
|
355 |
+
gr.update(interactive=bool(x.strip())),
|
356 |
+
gr.update(interactive=bool(x.strip()), variant="primary" if x.strip() else "secondary")
|
357 |
+
),
|
358 |
[msg],
|
359 |
[msg, submit]
|
360 |
)
|
361 |
|
362 |
+
# Example queries with emojis
|
363 |
gr.Examples(
|
364 |
examples=[
|
365 |
+
"π» Can Team A help me build a web application?",
|
366 |
+
"πΌ Create a new objective: Analyze market trends for AI startups",
|
367 |
+
"π Research the latest developments in quantum computing",
|
368 |
+
"π What's the current status of all teams?"
|
369 |
],
|
370 |
inputs=msg,
|
371 |
+
label="Example Queries",
|
372 |
+
examples_per_page=4
|
373 |
)
|
374 |
|
375 |
return interface
|