Richard Young Claude commited on
Commit
9f3663d
·
1 Parent(s): cb8e322

Fix 'tuple indices must be integers' error in ELA analysis

Browse files

- perform_ela_analysis returns tuple (is_suspicious, confidence, details)
- Updated to properly unpack all 3 return values
- Convert diff_image numpy array to PIL Image for display
- Handle case where ELA only works on JPEG (returns error for PNG)
- Fixes runtime error when analyzing images in Detect tab

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -128,8 +128,8 @@ def detect_hidden_data(image, sensitivity):
128
  # Perform analysis (returns: is_suspicious, confidence, details)
129
  is_suspicious, confidence, details = rat_finder.analyze_image(image_path, sensitivity=sensitivity_str)
130
 
131
- # Generate ELA visualization
132
- ela_result = rat_finder.perform_ela_analysis(image_path)
133
 
134
  # Clean up
135
  os.unlink(image_path)
@@ -183,11 +183,14 @@ def detect_hidden_data(image, sensitivity):
183
  Use the "Extract Data" tab if you suspect LSB steganography!
184
  """
185
 
186
- # Return ELA plot if available
187
- if ela_result['success'] and ela_result['ela_image']:
188
- return ela_result['ela_image'], result_text
 
 
 
189
 
190
- return None, result_text
191
 
192
  except Exception as e:
193
  if 'image_path' in locals() and os.path.exists(image_path):
 
128
  # Perform analysis (returns: is_suspicious, confidence, details)
129
  is_suspicious, confidence, details = rat_finder.analyze_image(image_path, sensitivity=sensitivity_str)
130
 
131
+ # Generate ELA visualization (returns: is_suspicious, confidence, details)
132
+ ela_is_suspicious, ela_confidence, ela_details = rat_finder.perform_ela_analysis(image_path)
133
 
134
  # Clean up
135
  os.unlink(image_path)
 
183
  Use the "Extract Data" tab if you suspect LSB steganography!
184
  """
185
 
186
+ # Return ELA plot if available (only for JPEG images)
187
+ ela_image = None
188
+ if isinstance(ela_details, dict) and 'diff_image' in ela_details and 'error' not in ela_details:
189
+ # Convert numpy array to PIL Image for display
190
+ diff_array = ela_details['diff_image']
191
+ ela_image = Image.fromarray(diff_array)
192
 
193
+ return ela_image, result_text
194
 
195
  except Exception as e:
196
  if 'image_path' in locals() and os.path.exists(image_path):