mohammedelfeky-ai commited on
Commit
3fe540b
·
verified ·
1 Parent(s): cb4e5b3

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +33 -21
Gradio_UI.py CHANGED
@@ -183,27 +183,39 @@ class GradioUI:
183
  self._latest_file_path_for_download = None
184
 
185
  def _check_for_created_file(self):
186
- self._latest_file_path_for_download = None
187
- if hasattr(self.agent, 'interaction_logs') and self.agent.interaction_logs:
188
- print(f"DEBUG Gradio UI: Checking {len(self.agent.interaction_logs)} interaction log entries for created files.")
189
- for log_entry in reversed(self.agent.interaction_logs):
190
- if isinstance(log_entry, ActionStep):
191
- observations = getattr(log_entry, 'observations', None)
192
- if observations and isinstance(observations, str):
193
- print(f"DEBUG Gradio UI: Checking observations: {observations[:200]}")
194
- path_match = re.search(r"(/tmp/[a-zA-Z0-9_]+/generated_document\.(?:docx|pdf|txt))", observations)
195
- if path_match:
196
- extracted_path = path_match.group(1)
197
- normalized_path = os.path.normpath(extracted_path)
198
- if os.path.exists(normalized_path):
199
- self._latest_file_path_for_download = normalized_path
200
- print(f"DEBUG Gradio UI: File path for download set (from observations): {self._latest_file_path_for_download}")
201
- return True
202
- else:
203
- print(f"DEBUG Gradio UI: Path from observations ('{normalized_path}') does not exist.")
204
- print("DEBUG Gradio UI: No valid generated file path found in agent logs for download.")
205
- return False
206
-
 
 
 
 
 
 
 
 
 
 
 
 
207
  def interact_with_agent(self, prompt_text: str, current_chat_history: list):
208
  print(f"DEBUG Gradio: interact_with_agent called with prompt: '{prompt_text}'")
209
  print(f"DEBUG Gradio: Current chat history (input type {type(current_chat_history)}): {current_chat_history}")
 
183
  self._latest_file_path_for_download = None
184
 
185
  def _check_for_created_file(self):
186
+ self._latest_file_path_for_download = None
187
+ if hasattr(self.agent, 'interaction_logs') and self.agent.interaction_logs:
188
+ print(f"DEBUG Gradio UI: Checking {len(self.agent.interaction_logs)} interaction log entries for created files.")
189
+ for log_entry in reversed(self.agent.interaction_logs):
190
+ if isinstance(log_entry, ActionStep):
191
+ observations = getattr(log_entry, 'observations', None)
192
+
193
+ if observations and isinstance(observations, str):
194
+ print(f"DEBUG Gradio UI: Log Entry Observations (for file check): {observations[:300]}") # Log more
195
+
196
+ # Regex to find paths specifically printed by our create_document tool
197
+ # It prints "Document created (docx): /path/to/file"
198
+ # or "Document created (txt): /path/to/file"
199
+ # or "Document converted to PDF: /path/to/file"
200
+ match = re.search(
201
+ r"(?:Document created \((?:docx|pdf|txt)\):|Document converted to PDF:)\s*(/tmp/[a-zA-Z0-9_]+/generated_document\.(?:docx|pdf|txt))",
202
+ observations
203
+ )
204
+
205
+ if match:
206
+ extracted_path = match.group(1) # Group 1 is the path
207
+ normalized_path = os.path.normpath(extracted_path)
208
+ if os.path.exists(normalized_path):
209
+ self._latest_file_path_for_download = normalized_path
210
+ print(f"DEBUG Gradio UI: File path for download set (from create_document output): {self._latest_file_path_for_download}")
211
+ return True
212
+ else:
213
+ print(f"DEBUG Gradio UI: Path from create_document output ('{normalized_path}') does not exist.")
214
+ # else: # Optional: Log if no match for create_document output specifically
215
+ # print(f"DEBUG Gradio UI: No 'create_document' output pattern found in these observations.")
216
+ print("DEBUG Gradio UI: No valid generated file path (from create_document) found in agent logs for download.")
217
+ return False
218
+
219
  def interact_with_agent(self, prompt_text: str, current_chat_history: list):
220
  print(f"DEBUG Gradio: interact_with_agent called with prompt: '{prompt_text}'")
221
  print(f"DEBUG Gradio: Current chat history (input type {type(current_chat_history)}): {current_chat_history}")