tatianija commited on
Commit
2f26c23
·
verified ·
1 Parent(s): d956b01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -34
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, attachment_name) -> 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)
@@ -480,43 +480,22 @@ class IntelligentAgent:
480
 
481
  # Create temporary directory for attachments
482
  temp_dir = tempfile.mkdtemp(prefix="agent_attachments_")
483
-
484
- # Check for attachments in various fields
485
- attachments = []
486
-
487
- for field in [attachment_name]:
488
- if field in question_data:
489
- field_data = question_data[field]
490
- if isinstance(field_data, list):
491
- attachments.extend(field_data)
492
- elif field_data: # Non-empty data
493
- attachments.append(field_data)
494
-
495
- # Process each attachment
496
- for i, attachment in enumerate(attachments):
497
- try:
498
- # Determine file name
499
- file_name = None
500
- file_type = ''
501
-
502
- if isinstance(attachment, dict):
503
- # Extract metadata if available
504
- file_name = attachment.get('name') or attachment.get('filename') or f"attachment_{i}"
505
- file_type = attachment.get('type', '').lower() or attachment.get('mime_type', '').lower()
506
- else:
507
- file_name = f"attachment_{i}"
508
 
509
- # Save attachment to file
510
- file_path = save_attachment_to_file(attachment, temp_dir, file_name)
511
 
512
- if not file_path:
513
- continue
514
 
515
- # Categorize based on extension or type
516
- file_ext = Path(file_path).suffix.lower()
517
 
518
- # Determine category
519
- is_image = (
520
  'image' in file_type or
521
  file_ext in ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.tiff']
522
  )
 
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)
 
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
  )