Spaces:
Build error
Build error
change output
Browse files
app.py
CHANGED
|
@@ -51,19 +51,35 @@ def predict(data):
|
|
| 51 |
predictions = [x if x == max_count else 0 for x in predictions]
|
| 52 |
|
| 53 |
#Result
|
| 54 |
-
result = (
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
)
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
-
return
|
| 61 |
|
| 62 |
# 定义 Gradio 界面
|
| 63 |
iface = gr.Interface(
|
| 64 |
fn=predict,
|
| 65 |
inputs=gr.JSON(label="json file"),
|
| 66 |
-
outputs=gr.
|
| 67 |
title="Burnsync classifier",
|
| 68 |
description="Upload a JSON file with 6-channel IMU time series data to predict the action class."
|
| 69 |
)
|
|
|
|
| 51 |
predictions = [x if x == max_count else 0 for x in predictions]
|
| 52 |
|
| 53 |
#Result
|
| 54 |
+
# result = (
|
| 55 |
+
# f"bicep: {predictions[0]} | abs: {predictions[1]} | "
|
| 56 |
+
# f"chess: {predictions[2]} | legs: {predictions[3]}"
|
| 57 |
+
# )
|
| 58 |
+
class_names = ["dumbbells", "situps", "pushups", "squats"]
|
| 59 |
+
if max_count == 0:
|
| 60 |
+
# 沒有任何類別達到閾值
|
| 61 |
+
result_json = {
|
| 62 |
+
"type": None,
|
| 63 |
+
"reps": 0
|
| 64 |
+
}
|
| 65 |
+
else:
|
| 66 |
+
# 找出哪個類別擁有 max_count
|
| 67 |
+
# 如果有多個類別並列最高,這裡僅選第一個
|
| 68 |
+
max_index = predictions.index(max_count)
|
| 69 |
+
result_json = {
|
| 70 |
+
"type": class_names[max_index],
|
| 71 |
+
"reps": max_count
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
return result_json
|
| 75 |
except Exception as e:
|
| 76 |
+
return {"error": str(e)}
|
| 77 |
|
| 78 |
# 定义 Gradio 界面
|
| 79 |
iface = gr.Interface(
|
| 80 |
fn=predict,
|
| 81 |
inputs=gr.JSON(label="json file"),
|
| 82 |
+
outputs=gr.JSON(label="Prediction Result"),
|
| 83 |
title="Burnsync classifier",
|
| 84 |
description="Upload a JSON file with 6-channel IMU time series data to predict the action class."
|
| 85 |
)
|