Update app.py
Browse files
app.py
CHANGED
@@ -469,7 +469,7 @@ class IntelligentAgent:
|
|
469 |
|
470 |
return "\n\n" + "="*50 + "\n".join(formatted_content) + "\n" + "="*50
|
471 |
|
472 |
-
def _detect_and_process_direct_attachments(self, file_name: str,
|
473 |
"""
|
474 |
Detect and process a single attachment directly attached to a question (not as a URL).
|
475 |
Returns (image_files, audio_files, code_files)
|
@@ -482,10 +482,8 @@ class IntelligentAgent:
|
|
482 |
return image_files, audio_files, code_files
|
483 |
|
484 |
try:
|
485 |
-
api_url = DEFAULT_API_URL
|
486 |
-
files_url = f"{DEFAULT_API_URL}/files/"
|
487 |
# Construct the file path (assuming file is in the same directory)
|
488 |
-
file_path = os.path.join(
|
489 |
|
490 |
# Check if file exists
|
491 |
if not os.path.exists(file_path):
|
@@ -703,10 +701,23 @@ Answer with just "YES" if web search would be helpful, or "NO" if the available
|
|
703 |
|
704 |
attachment_name = question_data.get('file_name', '')
|
705 |
task_id = question_data.get('task_id', '')
|
|
|
706 |
if self.debug:
|
707 |
print(f"Attachment name from question_data: '{attachment_name}'")
|
708 |
-
|
709 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
710 |
|
711 |
# Process attachments to get context
|
712 |
attachment_context = self._process_attachments(image_files, audio_files, code_files)
|
|
|
469 |
|
470 |
return "\n\n" + "="*50 + "\n".join(formatted_content) + "\n" + "="*50
|
471 |
|
472 |
+
def _detect_and_process_direct_attachments(self, file_name: str, local_path: str) -> Tuple[List[str], List[str], List[str]]:
|
473 |
"""
|
474 |
Detect and process a single attachment directly attached to a question (not as a URL).
|
475 |
Returns (image_files, audio_files, code_files)
|
|
|
482 |
return image_files, audio_files, code_files
|
483 |
|
484 |
try:
|
|
|
|
|
485 |
# Construct the file path (assuming file is in the same directory)
|
486 |
+
file_path = os.path.join(local_path, file_name)
|
487 |
|
488 |
# Check if file exists
|
489 |
if not os.path.exists(file_path):
|
|
|
701 |
|
702 |
attachment_name = question_data.get('file_name', '')
|
703 |
task_id = question_data.get('task_id', '')
|
704 |
+
|
705 |
if self.debug:
|
706 |
print(f"Attachment name from question_data: '{attachment_name}'")
|
707 |
+
|
708 |
+
if self.debug and attachment_name:
|
709 |
+
print(f"Downloading attachment from: {download_url}")
|
710 |
+
|
711 |
+
if attachment_name:
|
712 |
+
download_url = f"{api_base_url}/files/{task_id}"
|
713 |
+
response = requests.get(download_url, timeout=30)
|
714 |
+
response.raise_for_status()
|
715 |
+
local_file_path = os.path.join(temp_dir, safe_filename)
|
716 |
+
|
717 |
+
with open(local_file_path, 'wb') as f:
|
718 |
+
f.write(response.content)
|
719 |
+
|
720 |
+
image_files, audio_files, code_files = self._detect_and_process_direct_attachments(attachment_name, local_file_path)
|
721 |
|
722 |
# Process attachments to get context
|
723 |
attachment_context = self._process_attachments(image_files, audio_files, code_files)
|