Amol Kaushik commited on
Commit
d742823
·
1 Parent(s): 4bce895

fixed some classification slider issues

Browse files
Files changed (1) hide show
  1. app.py +38 -6
app.py CHANGED
@@ -189,9 +189,18 @@ def load_example():
189
 
190
  try:
191
  df = pd.read_csv(DATA_PATH, sep=';', decimal=',')
192
- available_features = [f for f in FEATURE_NAMES if f in df.columns]
193
- sample = df[available_features].sample(1).values[0]
194
- return [float(x) for x in sample]
 
 
 
 
 
 
 
 
 
195
  except Exception as e:
196
  print(f"Error loading example: {e}")
197
  return [0.5] * len(FEATURE_NAMES)
@@ -203,9 +212,18 @@ def load_classification_example():
203
 
204
  try:
205
  df = pd.read_csv(DATA_PATH, sep=';', decimal=',')
206
- available_features = [f for f in CLASSIFICATION_FEATURE_NAMES if f in df.columns]
207
- sample = df[available_features].sample(1).values[0]
208
- return [float(x) for x in sample]
 
 
 
 
 
 
 
 
 
209
  except Exception as e:
210
  print(f"Error loading classification example: {e}")
211
  return [0.5] * len(CLASSIFICATION_FEATURE_NAMES)
@@ -260,18 +278,22 @@ def create_interface():
260
  angle_features = [n for n in FEATURE_NAMES if "Angle" in n]
261
  nasm_features = [n for n in FEATURE_NAMES if "NASM" in n]
262
  time_features = [n for n in FEATURE_NAMES if "Time" in n]
 
263
 
264
  angle_indices = [FEATURE_NAMES.index(f) for f in angle_features]
265
  nasm_indices = [FEATURE_NAMES.index(f) for f in nasm_features]
266
  time_indices = [FEATURE_NAMES.index(f) for f in time_features]
 
267
 
268
  if CLASSIFICATION_FEATURE_NAMES is not None:
269
  class_angle_features = [n for n in CLASSIFICATION_FEATURE_NAMES if "Angle" in n]
270
  class_nasm_features = [n for n in CLASSIFICATION_FEATURE_NAMES if "NASM" in n]
271
  class_time_features = [n for n in CLASSIFICATION_FEATURE_NAMES if "Time" in n]
 
272
  class_angle_indices = [CLASSIFICATION_FEATURE_NAMES.index(f) for f in class_angle_features]
273
  class_nasm_indices = [CLASSIFICATION_FEATURE_NAMES.index(f) for f in class_nasm_features]
274
  class_time_indices = [CLASSIFICATION_FEATURE_NAMES.index(f) for f in class_time_features]
 
275
 
276
  with gr.Blocks(title="Deep Squat Assessment") as demo:
277
  gr.Markdown("# Deep Squat Movement Assessment")
@@ -299,6 +321,11 @@ def create_interface():
299
  for idx in time_indices:
300
  inputs[idx].render()
301
 
 
 
 
 
 
302
  with gr.Column(scale=1):
303
  gr.Markdown("### Results")
304
  score_output = gr.Textbox(label="Predicted Score")
@@ -341,6 +368,11 @@ def create_interface():
341
  for idx in class_time_indices:
342
  classification_inputs[idx].render()
343
 
 
 
 
 
 
344
  with gr.Column(scale=1):
345
  gr.Markdown("### Results")
346
  class_output = gr.Textbox(label="Predicted Body Region")
 
189
 
190
  try:
191
  df = pd.read_csv(DATA_PATH, sep=';', decimal=',')
192
+ sample_row = df.sample(1)
193
+ # Return value for each feature, using 0.5 as default if feature not in dataset
194
+ result = []
195
+ for f in FEATURE_NAMES:
196
+ if f in df.columns:
197
+ val = float(sample_row[f].values[0])
198
+ # Clamp to valid slider range [0, 1]
199
+ val = max(0.0, min(1.0, val))
200
+ result.append(val)
201
+ else:
202
+ result.append(0.5)
203
+ return result
204
  except Exception as e:
205
  print(f"Error loading example: {e}")
206
  return [0.5] * len(FEATURE_NAMES)
 
212
 
213
  try:
214
  df = pd.read_csv(DATA_PATH, sep=';', decimal=',')
215
+ sample_row = df.sample(1)
216
+ # Return value for each feature, using 0.5 as default if feature not in dataset
217
+ result = []
218
+ for f in CLASSIFICATION_FEATURE_NAMES:
219
+ if f in df.columns:
220
+ val = float(sample_row[f].values[0])
221
+ # Clamp to valid slider range [0, 1]
222
+ val = max(0.0, min(1.0, val))
223
+ result.append(val)
224
+ else:
225
+ result.append(0.5)
226
+ return result
227
  except Exception as e:
228
  print(f"Error loading classification example: {e}")
229
  return [0.5] * len(CLASSIFICATION_FEATURE_NAMES)
 
278
  angle_features = [n for n in FEATURE_NAMES if "Angle" in n]
279
  nasm_features = [n for n in FEATURE_NAMES if "NASM" in n]
280
  time_features = [n for n in FEATURE_NAMES if "Time" in n]
281
+ other_features = [n for n in FEATURE_NAMES if "Angle" not in n and "NASM" not in n and "Time" not in n]
282
 
283
  angle_indices = [FEATURE_NAMES.index(f) for f in angle_features]
284
  nasm_indices = [FEATURE_NAMES.index(f) for f in nasm_features]
285
  time_indices = [FEATURE_NAMES.index(f) for f in time_features]
286
+ other_indices = [FEATURE_NAMES.index(f) for f in other_features]
287
 
288
  if CLASSIFICATION_FEATURE_NAMES is not None:
289
  class_angle_features = [n for n in CLASSIFICATION_FEATURE_NAMES if "Angle" in n]
290
  class_nasm_features = [n for n in CLASSIFICATION_FEATURE_NAMES if "NASM" in n]
291
  class_time_features = [n for n in CLASSIFICATION_FEATURE_NAMES if "Time" in n]
292
+ class_other_features = [n for n in CLASSIFICATION_FEATURE_NAMES if "Angle" not in n and "NASM" not in n and "Time" not in n]
293
  class_angle_indices = [CLASSIFICATION_FEATURE_NAMES.index(f) for f in class_angle_features]
294
  class_nasm_indices = [CLASSIFICATION_FEATURE_NAMES.index(f) for f in class_nasm_features]
295
  class_time_indices = [CLASSIFICATION_FEATURE_NAMES.index(f) for f in class_time_features]
296
+ class_other_indices = [CLASSIFICATION_FEATURE_NAMES.index(f) for f in class_other_features]
297
 
298
  with gr.Blocks(title="Deep Squat Assessment") as demo:
299
  gr.Markdown("# Deep Squat Movement Assessment")
 
321
  for idx in time_indices:
322
  inputs[idx].render()
323
 
324
+ if other_indices:
325
+ with gr.TabItem(f"Other ({len(other_indices)})"):
326
+ for idx in other_indices:
327
+ inputs[idx].render()
328
+
329
  with gr.Column(scale=1):
330
  gr.Markdown("### Results")
331
  score_output = gr.Textbox(label="Predicted Score")
 
368
  for idx in class_time_indices:
369
  classification_inputs[idx].render()
370
 
371
+ if class_other_indices:
372
+ with gr.TabItem(f"Other ({len(class_other_indices)})"):
373
+ for idx in class_other_indices:
374
+ classification_inputs[idx].render()
375
+
376
  with gr.Column(scale=1):
377
  gr.Markdown("### Results")
378
  class_output = gr.Textbox(label="Predicted Body Region")