swastikbansal commited on
Commit
497bfdb
·
1 Parent(s): 4edcdd3

Refactor process_image to always return a tuple (dict, img) for consistency and safety

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -148,7 +148,8 @@ def process_image(img):
148
  # Determine the number of available sources (hand(s)/pose)
149
  num_sources = sum(prob is not None for prob in [left_probs, right_probs, pose_probs])
150
  if num_sources == 0:
151
- return {"message": "No valid data", "frame_count": frame_count}
 
152
 
153
  avg = (left_probs_aligned + right_probs_aligned + pose_probs_aligned) / (100 * num_sources)
154
 
@@ -167,7 +168,8 @@ def process_image(img):
167
  accumulated_probs = None
168
  frame_count = 0
169
 
170
- return {"prediction": pred} if pred else {"message": "Collecting frames", "frame_count": frame_count}, img
 
171
 
172
  @app.route('/process_frame', methods=['POST'])
173
  def process_video_frame():
@@ -196,7 +198,13 @@ def process_video_frame():
196
  pass
197
 
198
  # Process the image to get a prediction
199
- result, annotated_img = process_image(img)
 
 
 
 
 
 
200
 
201
  if result.get("prediction"):
202
  # Clear the queue as we have a final prediction
 
148
  # Determine the number of available sources (hand(s)/pose)
149
  num_sources = sum(prob is not None for prob in [left_probs, right_probs, pose_probs])
150
  if num_sources == 0:
151
+ # Always return a tuple (dict, img) to keep the caller safe
152
+ return {"message": "No valid data", "frame_count": frame_count}, img
153
 
154
  avg = (left_probs_aligned + right_probs_aligned + pose_probs_aligned) / (100 * num_sources)
155
 
 
168
  accumulated_probs = None
169
  frame_count = 0
170
 
171
+ # Make the tuple return explicit (avoid precedence surprises)
172
+ return ({"prediction": pred} if pred else {"message": "Collecting frames", "frame_count": frame_count}), img
173
 
174
  @app.route('/process_frame', methods=['POST'])
175
  def process_video_frame():
 
198
  pass
199
 
200
  # Process the image to get a prediction
201
+ ret = process_image(img)
202
+ # Defensive unpack: process_image should return (dict, img) now, but handle older behavior gracefully
203
+ if isinstance(ret, tuple) and len(ret) == 2:
204
+ result, annotated_img = ret
205
+ else:
206
+ result = ret
207
+ annotated_img = img
208
 
209
  if result.get("prediction"):
210
  # Clear the queue as we have a final prediction