tatianija commited on
Commit
fa22f1c
·
verified ·
1 Parent(s): 4a0d2ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -35
app.py CHANGED
@@ -469,64 +469,65 @@ class IntelligentAgent:
469
 
470
  return "\n\n" + "="*50 + "\n".join(formatted_content) + "\n" + "="*50
471
 
472
- def _detect_and_process_direct_attachments(self, attachment_name: str) -> Tuple[List[str], List[str], List[str]]:
473
  """
474
- Detect and process attachments that are directly attached to questions (not as URLs).
475
  Returns (image_files, audio_files, code_files)
476
  """
477
  image_files = []
478
  audio_files = []
479
  code_files = []
480
-
481
  # Create temporary directory for attachments
482
  temp_dir = tempfile.mkdtemp(prefix="agent_attachments_")
483
-
484
- # Process attachment
485
  try:
 
 
486
  file_type = ''
487
-
488
  # Save attachment to file
489
- file_path = save_attachment_to_file(file_name, temp_dir, file_name)
490
-
491
  if not file_path:
492
- continue
493
-
494
- # Categorize based on extension or type
 
 
495
  file_ext = Path(file_path).suffix.lower()
496
-
497
  # Determine category
498
  is_image = (
499
- 'image' in file_type or
500
- file_ext in ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.tiff']
501
- )
502
  is_audio = (
503
- 'audio' in file_type or
504
- file_ext in ['.mp3', '.wav', '.m4a', '.ogg', '.flac', '.aac']
505
- )
506
  is_code = (
507
- 'python' in file_type or 'code' in file_type or 'text' in file_type or
508
- file_ext in ['.py', '.txt', '.js', '.html', '.css', '.json', '.xml']
509
- )
510
-
511
  # Categorize the file
512
  if is_image:
513
- image_files.append(file_path)
514
  elif is_audio:
515
- audio_files.append(file_path)
516
  elif is_code:
517
- code_files.append(file_path)
518
  else:
519
- # Default to code/text for unknown types
520
- code_files.append(file_path)
521
-
522
  except Exception as e:
523
- if self.debug:
524
- print(f"Error processing attachment {i}: {e}")
525
- continue
526
-
527
- if self.debug:
528
- print(f"...Found direct attachments: {len(image_files)} images, {len(audio_files)} audio, {len(code_files)} code files")
529
-
530
  return image_files, audio_files, code_files
531
 
532
  def _process_attachments(self, image_files: List[str] = None, audio_files: List[str] = None, code_files: List[str] = None) -> str:
 
469
 
470
  return "\n\n" + "="*50 + "\n".join(formatted_content) + "\n" + "="*50
471
 
472
+ def _detect_and_process_direct_attachment(self, attachment_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)
476
  """
477
  image_files = []
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(file_path).suffix.lower()
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
+
513
  # Categorize the file
514
  if is_image:
515
+ image_files.append(file_path)
516
  elif is_audio:
517
+ audio_files.append(file_path)
518
  elif is_code:
519
+ code_files.append(file_path)
520
  else:
521
+ # Default to code/text for unknown types
522
+ code_files.append(file_path)
523
+
524
  except Exception as e:
525
+ if getattr(self, 'debug', False):
526
+ print(f"Error processing attachment {attachment_name}: {e}")
527
+
528
+ if getattr(self, 'debug', False):
529
+ print(f"...Processed attachment: {len(image_files)} images, {len(audio_files)} audio, {len(code_files)} code files")
530
+
 
531
  return image_files, audio_files, code_files
532
 
533
  def _process_attachments(self, image_files: List[str] = None, audio_files: List[str] = None, code_files: List[str] = None) -> str: