Spaces:
Paused
Paused
Create a new agent per session to isolate session conversation with others session
Browse files- Gradio_UI.py +9 -3
Gradio_UI.py
CHANGED
@@ -192,12 +192,17 @@ class GradioUI:
|
|
192 |
if not os.path.exists(file_upload_folder):
|
193 |
os.mkdir(file_upload_folder)
|
194 |
|
195 |
-
def interact_with_agent(self, prompt, messages):
|
196 |
import gradio as gr
|
197 |
|
|
|
|
|
|
|
|
|
|
|
198 |
messages.append(gr.ChatMessage(role="user", content=prompt))
|
199 |
yield messages
|
200 |
-
for msg in stream_to_gradio(
|
201 |
messages.append(msg)
|
202 |
yield messages
|
203 |
yield messages
|
@@ -267,6 +272,7 @@ class GradioUI:
|
|
267 |
with gr.Blocks(fill_height=True) as demo:
|
268 |
# user_state = gr.State(random.random) # to avoid sharing gr.State across users (that uses all the users conversations for any user prompts)
|
269 |
gr.Label("Welcome to my first smolagent! You can use tools to get the time in a location, visit a URL page, search with DuckDuckGo.")
|
|
|
270 |
stored_messages = gr.State([])
|
271 |
file_uploads_log = gr.State([])
|
272 |
chatbot = gr.Chatbot(
|
@@ -293,7 +299,7 @@ class GradioUI:
|
|
293 |
self.log_user_message,
|
294 |
[text_input, file_uploads_log],
|
295 |
[stored_messages, text_input],
|
296 |
-
).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])
|
297 |
# Initialize instance when page loads
|
298 |
demo.load(random.random, inputs=None, outputs=None)
|
299 |
|
|
|
192 |
if not os.path.exists(file_upload_folder):
|
193 |
os.mkdir(file_upload_folder)
|
194 |
|
195 |
+
def interact_with_agent(self, prompt, messages, session_state):
|
196 |
import gradio as gr
|
197 |
|
198 |
+
# Get the agent type from the template agent
|
199 |
+
if "agent" not in session_state:
|
200 |
+
from copy import deepcopy
|
201 |
+
session_state["agent"] = deepcopy(self.agent)
|
202 |
+
|
203 |
messages.append(gr.ChatMessage(role="user", content=prompt))
|
204 |
yield messages
|
205 |
+
for msg in stream_to_gradio(session_state["agent"], task=prompt, reset_agent_memory=False):
|
206 |
messages.append(msg)
|
207 |
yield messages
|
208 |
yield messages
|
|
|
272 |
with gr.Blocks(fill_height=True) as demo:
|
273 |
# user_state = gr.State(random.random) # to avoid sharing gr.State across users (that uses all the users conversations for any user prompts)
|
274 |
gr.Label("Welcome to my first smolagent! You can use tools to get the time in a location, visit a URL page, search with DuckDuckGo.")
|
275 |
+
session_state = gr.State({})
|
276 |
stored_messages = gr.State([])
|
277 |
file_uploads_log = gr.State([])
|
278 |
chatbot = gr.Chatbot(
|
|
|
299 |
self.log_user_message,
|
300 |
[text_input, file_uploads_log],
|
301 |
[stored_messages, text_input],
|
302 |
+
).then(self.interact_with_agent, [stored_messages, chatbot, session_state], [chatbot])
|
303 |
# Initialize instance when page loads
|
304 |
demo.load(random.random, inputs=None, outputs=None)
|
305 |
|