acidtib commited on
Commit
ac7d2bc
·
1 Parent(s): a6eb016

✨ feat: add loading message during agent interaction

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +33 -2
Gradio_UI.py CHANGED
@@ -192,11 +192,30 @@ class GradioUI:
192
  def interact_with_agent(self, prompt, messages):
193
  import gradio as gr
194
 
 
195
  messages.append(gr.ChatMessage(role="user", content=prompt))
196
  yield messages
 
 
 
 
 
 
 
 
 
 
 
197
  for msg in stream_to_gradio(self.agent, task=prompt, reset_agent_memory=False):
 
 
 
198
  messages.append(msg)
199
  yield messages
 
 
 
 
200
  yield messages
201
 
202
  def upload_file(
@@ -261,7 +280,19 @@ class GradioUI:
261
  def launch(self, **kwargs):
262
  import gradio as gr
263
 
264
- with gr.Blocks(title="Travel Planning Agent", fill_height=True) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
265
  gr.Markdown(
266
  """
267
  # Travel Planning Agent
@@ -312,4 +343,4 @@ class GradioUI:
312
  demo.launch(debug=True, share=True, **kwargs)
313
 
314
 
315
- __all__ = ["stream_to_gradio", "GradioUI"]
 
192
  def interact_with_agent(self, prompt, messages):
193
  import gradio as gr
194
 
195
+ # Add user message
196
  messages.append(gr.ChatMessage(role="user", content=prompt))
197
  yield messages
198
+
199
+ # Add loading message
200
+ loading_msg = gr.ChatMessage(
201
+ role="assistant",
202
+ content="🤔 Thinking...",
203
+ metadata={"class": "loading-message"}
204
+ )
205
+ messages.append(loading_msg)
206
+ yield messages
207
+
208
+ # Process agent response
209
  for msg in stream_to_gradio(self.agent, task=prompt, reset_agent_memory=False):
210
+ # Remove loading message before adding real responses
211
+ if len(messages) > 0 and messages[-1].metadata.get("class") == "loading-message":
212
+ messages.pop()
213
  messages.append(msg)
214
  yield messages
215
+
216
+ # Ensure loading message is removed at the end
217
+ if len(messages) > 0 and messages[-1].metadata.get("class") == "loading-message":
218
+ messages.pop()
219
  yield messages
220
 
221
  def upload_file(
 
280
  def launch(self, **kwargs):
281
  import gradio as gr
282
 
283
+ with gr.Blocks(
284
+ title="Travel Planning Agent",
285
+ fill_height=True,
286
+ css="""
287
+ .loading-message {
288
+ animation: pulse 2s cubic-bezier(.4,0,.6,1) infinite;
289
+ }
290
+ @keyframes pulse {
291
+ 0%, 100% { opacity: 1; }
292
+ 50% { opacity: 0.5; }
293
+ }
294
+ """
295
+ ) as demo:
296
  gr.Markdown(
297
  """
298
  # Travel Planning Agent
 
343
  demo.launch(debug=True, share=True, **kwargs)
344
 
345
 
346
+ __all__ = ["stream_to_gradio", "GradioUI"]