Update Gradio_UI.py
Browse files- 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 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 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}")
|