Update Gradio_UI.py
Browse files- Gradio_UI.py +5 -10
Gradio_UI.py
CHANGED
@@ -148,9 +148,7 @@ def stream_to_gradio(
|
|
148 |
step_log.input_token_count = agent.model.last_input_token_count
|
149 |
step_log.output_token_count = agent.model.last_output_token_count
|
150 |
|
151 |
-
for message in pull_messages_from_step(
|
152 |
-
step_log,
|
153 |
-
):
|
154 |
yield message
|
155 |
|
156 |
final_answer = step_log # Last log is the run's final_answer
|
@@ -227,15 +225,11 @@ class GradioUI:
|
|
227 |
|
228 |
# Sanitize file name
|
229 |
original_name = os.path.basename(file.name)
|
230 |
-
sanitized_name = re.sub(
|
231 |
-
r"[^\w\-.]", "_", original_name
|
232 |
-
) # Replace any non-alphanumeric, non-dash, or non-dot characters with underscores
|
233 |
-
|
234 |
type_to_ext = {}
|
235 |
for ext, t in mimetypes.types_map.items():
|
236 |
if t not in type_to_ext:
|
237 |
type_to_ext[t] = ext
|
238 |
-
|
239 |
# Ensure the extension correlates to the mime type
|
240 |
sanitized_name = sanitized_name.split(".")[:-1]
|
241 |
sanitized_name.append("" + type_to_ext[mime_type])
|
@@ -262,7 +256,8 @@ class GradioUI:
|
|
262 |
import gradio as gr
|
263 |
|
264 |
with gr.Blocks(fill_height=True) as demo:
|
265 |
-
stored_messages
|
|
|
266 |
file_uploads_log = gr.State([])
|
267 |
chatbot = gr.Chatbot(
|
268 |
label="Agent",
|
@@ -293,4 +288,4 @@ class GradioUI:
|
|
293 |
demo.launch(debug=True, share=True, **kwargs)
|
294 |
|
295 |
|
296 |
-
__all__ = ["stream_to_gradio", "GradioUI"]
|
|
|
148 |
step_log.input_token_count = agent.model.last_input_token_count
|
149 |
step_log.output_token_count = agent.model.last_output_token_count
|
150 |
|
151 |
+
for message in pull_messages_from_step(step_log):
|
|
|
|
|
152 |
yield message
|
153 |
|
154 |
final_answer = step_log # Last log is the run's final_answer
|
|
|
225 |
|
226 |
# Sanitize file name
|
227 |
original_name = os.path.basename(file.name)
|
228 |
+
sanitized_name = re.sub(r"[^\w\-.]", "_", original_name)
|
|
|
|
|
|
|
229 |
type_to_ext = {}
|
230 |
for ext, t in mimetypes.types_map.items():
|
231 |
if t not in type_to_ext:
|
232 |
type_to_ext[t] = ext
|
|
|
233 |
# Ensure the extension correlates to the mime type
|
234 |
sanitized_name = sanitized_name.split(".")[:-1]
|
235 |
sanitized_name.append("" + type_to_ext[mime_type])
|
|
|
256 |
import gradio as gr
|
257 |
|
258 |
with gr.Blocks(fill_height=True) as demo:
|
259 |
+
# Initialize stored_messages with the agent's conversation (including the initial opener)
|
260 |
+
stored_messages = gr.State(value=self.agent.conversation)
|
261 |
file_uploads_log = gr.State([])
|
262 |
chatbot = gr.Chatbot(
|
263 |
label="Agent",
|
|
|
288 |
demo.launch(debug=True, share=True, **kwargs)
|
289 |
|
290 |
|
291 |
+
__all__ = ["stream_to_gradio", "GradioUI"]
|