Spaces:
Sleeping
Sleeping
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_attachment(self,
|
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)
|
@@ -478,35 +478,20 @@ class IntelligentAgent:
|
|
478 |
audio_files = []
|
479 |
code_files = []
|
480 |
|
481 |
-
# Create temporary directory for attachments
|
482 |
-
temp_dir = tempfile.mkdtemp(prefix="agent_attachments_")
|
483 |
-
|
484 |
try:
|
485 |
# Here, file_type should ideally come from metadata or inferred from content —
|
486 |
# since only attachment_name is passed, we'll rely on the file extension.
|
487 |
-
file_type = ''
|
488 |
-
|
489 |
-
# Save attachment to file
|
490 |
-
file_path = save_attachment_to_file(attachment_name, temp_dir, attachment_name)
|
491 |
-
if not file_path:
|
492 |
-
if getattr(self, 'debug', False):
|
493 |
-
print(f"Failed to save attachment: {attachment_name}")
|
494 |
-
return image_files, audio_files, code_files
|
495 |
-
|
496 |
# Get file extension
|
497 |
-
file_ext = Path(
|
498 |
|
499 |
# Determine category
|
500 |
-
is_image = (
|
501 |
-
'image' in file_type or
|
502 |
file_ext in ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.tiff']
|
503 |
)
|
504 |
-
is_audio = (
|
505 |
-
'audio' in file_type or
|
506 |
file_ext in ['.mp3', '.wav', '.m4a', '.ogg', '.flac', '.aac']
|
507 |
)
|
508 |
is_code = (
|
509 |
-
'python' in file_type or 'code' in file_type or 'text' in file_type or
|
510 |
file_ext in ['.py', '.txt', '.js', '.html', '.css', '.json', '.xml']
|
511 |
)
|
512 |
|
|
|
469 |
|
470 |
return "\n\n" + "="*50 + "\n".join(formatted_content) + "\n" + "="*50
|
471 |
|
472 |
+
def _detect_and_process_direct_attachment(self, file_name: 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)
|
|
|
478 |
audio_files = []
|
479 |
code_files = []
|
480 |
|
|
|
|
|
|
|
481 |
try:
|
482 |
# Here, file_type should ideally come from metadata or inferred from content —
|
483 |
# since only attachment_name is passed, we'll rely on the file extension.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
# Get file extension
|
485 |
+
file_ext = Path(file_name).suffix.lower()
|
486 |
|
487 |
# Determine category
|
488 |
+
is_image = (
|
|
|
489 |
file_ext in ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.tiff']
|
490 |
)
|
491 |
+
is_audio = (
|
|
|
492 |
file_ext in ['.mp3', '.wav', '.m4a', '.ogg', '.flac', '.aac']
|
493 |
)
|
494 |
is_code = (
|
|
|
495 |
file_ext in ['.py', '.txt', '.js', '.html', '.css', '.json', '.xml']
|
496 |
)
|
497 |
|