Hiba03 commited on
Commit
1ac0a65
·
verified ·
1 Parent(s): 38b4b88

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +11 -5
Gradio_UI.py CHANGED
@@ -136,18 +136,24 @@ def stream_to_gradio(
136
  )
137
  import gradio as gr
138
 
 
139
  total_input_tokens = 0
140
  total_output_tokens = 0
141
-
 
142
  for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args):
143
  # Track tokens if model provides them
144
- if hasattr(agent.model, "last_input_token_count"):
145
  total_input_tokens += agent.model.last_input_token_count
 
146
  total_output_tokens += agent.model.last_output_token_count
147
- if isinstance(step_log, ActionStep):
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
  ):
 
136
  )
137
  import gradio as gr
138
 
139
+ # Initialize token counters
140
  total_input_tokens = 0
141
  total_output_tokens = 0
142
+
143
+ # Iterate over the agent run logs
144
  for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args):
145
  # Track tokens if model provides them
146
+ if hasattr(agent.model, "last_input_token_count") and agent.model.last_input_token_count is not None:
147
  total_input_tokens += agent.model.last_input_token_count
148
+ if hasattr(agent.model, "last_output_token_count") and agent.model.last_output_token_count is not None:
149
  total_output_tokens += agent.model.last_output_token_count
150
+
151
+ # Store token counts in step logs if it's an ActionStep
152
+ if isinstance(step_log, ActionStep):
153
+ step_log.input_token_count = agent.model.last_input_token_count if hasattr(agent.model, "last_input_token_count") else 0
154
+ step_log.output_token_count = agent.model.last_output_token_count if hasattr(agent.model, "last_output_token_count") else 0
155
 
156
+
157
  for message in pull_messages_from_step(
158
  step_log,
159
  ):