Athagi commited on
Commit
9ef59d2
·
1 Parent(s): bf2fc31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -6,7 +6,7 @@ from insightface.app import FaceAnalysis
6
  import onnxruntime
7
  from PIL import Image
8
  import tempfile
9
- import math # Import math for debugging if needed, but not directly used in the fixed slider logic
10
 
11
  # --- Global Configurations and Model Loading ---
12
  # Determine the appropriate provider for ONNX Runtime.
@@ -143,9 +143,16 @@ def update_faces_preview(target_img_pil: Image.Image):
143
  preview_img_bgr = draw_faces(target_np_bgr, faces)
144
  preview_img_rgb = cv2.cvtColor(preview_img_bgr, cv2.COLOR_BGR2RGB)
145
 
146
- # Set the max value of the slider to (number of faces - 1) as indices are 0-based
 
 
 
 
 
 
147
  # This ensures minimum=0 and maximum >= 0, avoiding the math domain error.
148
- return preview_img_rgb, gr.Slider(minimum=0, maximum=num_faces - 1, value=0, interactive=True), gr.File(value=None, interactive=False), f"Detected {num_faces} face(s). Select the face to swap using the slider (0-indexed)."
 
149
 
150
  def face_swap_simswap(source_img_pil: Image.Image, target_img_pil: Image.Image, face_index: int):
151
  """
 
6
  import onnxruntime
7
  from PIL import Image
8
  import tempfile
9
+ # import math # Not directly needed for the fixed slider logic, keep it if you need it for other debug/math operations
10
 
11
  # --- Global Configurations and Model Loading ---
12
  # Determine the appropriate provider for ONNX Runtime.
 
143
  preview_img_bgr = draw_faces(target_np_bgr, faces)
144
  preview_img_rgb = cv2.cvtColor(preview_img_bgr, cv2.COLOR_BGR2RGB)
145
 
146
+ # FIX: Handle num_faces = 1 explicitly for slider interactivity
147
+ slider_max = num_faces - 1
148
+ slider_interactive = True
149
+ if num_faces == 1:
150
+ slider_interactive = False # No need to slide if only one face (index 0)
151
+
152
+ # Set the max value of the slider to (num_faces - 1) as indices are 0-based.
153
  # This ensures minimum=0 and maximum >= 0, avoiding the math domain error.
154
+ # The `interactive` flag helps prevent `log10(0)` when only one option exists.
155
+ return preview_img_rgb, gr.Slider(minimum=0, maximum=slider_max, value=0, interactive=slider_interactive), gr.File(value=None, interactive=False), f"Detected {num_faces} face(s). Select the face to swap using the slider (0-indexed)."
156
 
157
  def face_swap_simswap(source_img_pil: Image.Image, target_img_pil: Image.Image, face_index: int):
158
  """