m-ric HF Staff commited on
Commit
aeeb12a
·
verified ·
1 Parent(s): ef3d985

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -42
app.py CHANGED
@@ -20,7 +20,7 @@ from smolagents.agent_types import (
20
  AgentText,
21
  handle_agent_output_types,
22
  )
23
- from smolagents.gradio_ui import pull_messages_from_step
24
 
25
  from scripts.text_inspector_tool import TextInspectorTool
26
  from scripts.text_web_browser import (
@@ -160,9 +160,6 @@ AUTHORIZED_IMPORTS = [
160
  load_dotenv(override=True)
161
  login(os.getenv("HF_TOKEN"))
162
 
163
-
164
- print("TOKKKK", os.getenv("HF_TOKEN")[-10:])
165
-
166
  append_answer_lock = threading.Lock()
167
 
168
  custom_role_conversions = {"tool-call": "assistant", "tool-response": "user"}
@@ -218,44 +215,6 @@ def create_agent():
218
  document_inspection_tool = TextInspectorTool(model, 20000)
219
 
220
 
221
- def stream_to_gradio(
222
- agent,
223
- task: str,
224
- reset_agent_memory: bool = False,
225
- additional_args: Optional[dict] = None,
226
- ):
227
- """Runs an agent with the given task and streams the messages from the agent as gradio ChatMessages."""
228
- for step_log in agent.run(
229
- task, stream=True, reset=reset_agent_memory, additional_args=additional_args
230
- ):
231
- for message in pull_messages_from_step(
232
- step_log,
233
- ):
234
- yield message
235
-
236
- final_answer = handle_agent_output_types(step_log.content) # Last log is the run's final_answer
237
-
238
- if isinstance(final_answer, AgentText):
239
- yield gr.ChatMessage(
240
- role="assistant",
241
- content=f"**Final answer:**\n{final_answer.to_string()}\n",
242
- )
243
- elif isinstance(final_answer, AgentImage):
244
- yield gr.ChatMessage(
245
- role="assistant",
246
- content={"path": final_answer.to_string(), "mime_type": "image/png"},
247
- )
248
- elif isinstance(final_answer, AgentAudio):
249
- yield gr.ChatMessage(
250
- role="assistant",
251
- content={"path": final_answer.to_string(), "mime_type": "audio/wav"},
252
- )
253
- else:
254
- yield gr.ChatMessage(
255
- role="assistant", content=f"**Final answer:** {str(final_answer)}"
256
- )
257
-
258
-
259
  class GradioUI:
260
  """A one-line interface to launch your agent in Gradio"""
261
 
 
20
  AgentText,
21
  handle_agent_output_types,
22
  )
23
+ from smolagents.gradio_ui import stream_to_gradio
24
 
25
  from scripts.text_inspector_tool import TextInspectorTool
26
  from scripts.text_web_browser import (
 
160
  load_dotenv(override=True)
161
  login(os.getenv("HF_TOKEN"))
162
 
 
 
 
163
  append_answer_lock = threading.Lock()
164
 
165
  custom_role_conversions = {"tool-call": "assistant", "tool-response": "user"}
 
215
  document_inspection_tool = TextInspectorTool(model, 20000)
216
 
217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  class GradioUI:
219
  """A one-line interface to launch your agent in Gradio"""
220