Firoj112 commited on
Commit
401be78
·
verified ·
1 Parent(s): 2db16da

Update GRADIO_UI.py

Browse files
Files changed (1) hide show
  1. GRADIO_UI.py +8 -8
GRADIO_UI.py CHANGED
@@ -175,15 +175,16 @@ class GradioUI:
175
  if not _is_package_available("gradio"):
176
  raise ModuleNotFoundError("Please install 'gradio' extra to use the GradioUI: `pip install 'smolagents[gradio]'`")
177
  self.initialize_agent = initialize_agent
 
178
 
179
- def interact_with_agent(self, prompt, api_key, messages):
180
  import gradio as gr
181
- messages.append(gr.ChatMessage(role="user", content=prompt))
182
- yield messages
183
  for msg in stream_to_gradio(self.initialize_agent, task=prompt, api_key=api_key, reset_agent_memory=False):
184
- messages.append(msg)
185
- yield messages
186
- yield messages
187
 
188
  def launch(self, **kwargs):
189
  import gradio as gr
@@ -217,8 +218,7 @@ class GradioUI:
217
  text_input = gr.Textbox(
218
  lines=1, label="Enter URL and request (e.g., navigate to https://en.wikipedia.org/wiki/Nvidia, and provide me info on its history)"
219
  )
220
- messages = []
221
- text_input.submit(self.interact_with_agent, [text_input, api_key_input, messages], [chatbot])
222
 
223
  demo.launch(debug=True, **kwargs)
224
 
 
175
  if not _is_package_available("gradio"):
176
  raise ModuleNotFoundError("Please install 'gradio' extra to use the GradioUI: `pip install 'smolagents[gradio]'`")
177
  self.initialize_agent = initialize_agent
178
+ self.messages = [] # Initialize messages as a class attribute
179
 
180
+ def interact_with_agent(self, prompt, api_key):
181
  import gradio as gr
182
+ self.messages.append(gr.ChatMessage(role="user", content=prompt))
183
+ yield self.messages
184
  for msg in stream_to_gradio(self.initialize_agent, task=prompt, api_key=api_key, reset_agent_memory=False):
185
+ self.messages.append(msg)
186
+ yield self.messages
187
+ yield self.messages
188
 
189
  def launch(self, **kwargs):
190
  import gradio as gr
 
218
  text_input = gr.Textbox(
219
  lines=1, label="Enter URL and request (e.g., navigate to https://en.wikipedia.org/wiki/Nvidia, and provide me info on its history)"
220
  )
221
+ text_input.submit(self.interact_with_agent, [text_input, api_key_input], [chatbot])
 
222
 
223
  demo.launch(debug=True, **kwargs)
224