Spaces:
Runtime error
Runtime error
UI adjustments..
Browse files- src/phyphox_app_block.py +11 -11
- src/streamlit_app.py +9 -9
src/phyphox_app_block.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""Streamlit UI block for Tab 2
|
| 2 |
|
| 3 |
Call from streamlit_app.py:
|
| 4 |
|
|
@@ -28,12 +28,12 @@ LABEL_MAP = {
|
|
| 28 |
}
|
| 29 |
|
| 30 |
EXPLANATIONS = {
|
| 31 |
-
"LAYING": "Minimal movement detected across all axes
|
| 32 |
-
"SITTING": "Low dynamic acceleration with stable gravity
|
| 33 |
"STANDING": "Similar to sitting with slight postural micro-movements.",
|
| 34 |
-
"WALKING": "Rhythmic periodic acceleration on the vertical axis
|
| 35 |
-
"WALKING_DOWNSTAIRS": "Downward gravitational shift with higher impact peaks
|
| 36 |
-
"WALKING_UPSTAIRS": "Elevated vertical acceleration effort
|
| 37 |
}
|
| 38 |
|
| 39 |
# ββ Normalisation βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -52,7 +52,7 @@ def _normalize(features: np.ndarray, min_vals: np.ndarray, max_vals: np.ndarray)
|
|
| 52 |
"""Best-effort feature-level min-max scaling to [-1, 1].
|
| 53 |
|
| 54 |
Uses per-feature min/max observed in the UCI HAR training set. This is
|
| 55 |
-
an approximation
|
| 56 |
extraction, so physical-unit features may fall outside the training range.
|
| 57 |
Values are clipped before scaling to keep outputs bounded.
|
| 58 |
"""
|
|
@@ -73,7 +73,7 @@ def render_phyphox_tab(
|
|
| 73 |
st.markdown("""
|
| 74 |
**How to record your own data:**
|
| 75 |
1. Install [Phyphox](https://phyphox.org/) on your phone
|
| 76 |
-
2. Open **Acceleration (without g)** and **Gyroscope**
|
| 77 |
3. Hold the phone at your waist (same position as the UCI dataset)
|
| 78 |
4. Record at least 3 seconds of a single activity
|
| 79 |
5. Export both experiments as CSV and upload below
|
|
@@ -135,13 +135,13 @@ def render_phyphox_tab(
|
|
| 135 |
)
|
| 136 |
else:
|
| 137 |
st.warning(
|
| 138 |
-
"norm_params.json not found
|
| 139 |
"Predictions will be unreliable until normalisation is applied."
|
| 140 |
)
|
| 141 |
|
| 142 |
# ββ Predictions βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 143 |
if ffn_status != "ready" and cnn_status != "ready":
|
| 144 |
-
st.warning("Models not loaded
|
| 145 |
return
|
| 146 |
|
| 147 |
st.markdown("---")
|
|
@@ -153,7 +153,7 @@ def render_phyphox_tab(
|
|
| 153 |
with col:
|
| 154 |
st.markdown(f"#### {name}")
|
| 155 |
if status != "ready":
|
| 156 |
-
st.error(f"Model not loaded
|
| 157 |
return
|
| 158 |
|
| 159 |
probs_all = model.predict(features, verbose=0) # (n_windows, 6)
|
|
|
|
| 1 |
+
"""Streamlit UI block for Tab 2: Phyphox live sensor upload.
|
| 2 |
|
| 3 |
Call from streamlit_app.py:
|
| 4 |
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
EXPLANATIONS = {
|
| 31 |
+
"LAYING": "Minimal movement detected across all axes: consistent with a stationary horizontal posture.",
|
| 32 |
+
"SITTING": "Low dynamic acceleration with stable gravity: stationary upright posture.",
|
| 33 |
"STANDING": "Similar to sitting with slight postural micro-movements.",
|
| 34 |
+
"WALKING": "Rhythmic periodic acceleration on the vertical axis: level walking at normal cadence.",
|
| 35 |
+
"WALKING_DOWNSTAIRS": "Downward gravitational shift with higher impact peaks: descending stairs.",
|
| 36 |
+
"WALKING_UPSTAIRS": "Elevated vertical acceleration effort: climbing stairs.",
|
| 37 |
}
|
| 38 |
|
| 39 |
# ββ Normalisation βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 52 |
"""Best-effort feature-level min-max scaling to [-1, 1].
|
| 53 |
|
| 54 |
Uses per-feature min/max observed in the UCI HAR training set. This is
|
| 55 |
+
an approximation: the UCI pipeline normalises raw signals before feature
|
| 56 |
extraction, so physical-unit features may fall outside the training range.
|
| 57 |
Values are clipped before scaling to keep outputs bounded.
|
| 58 |
"""
|
|
|
|
| 73 |
st.markdown("""
|
| 74 |
**How to record your own data:**
|
| 75 |
1. Install [Phyphox](https://phyphox.org/) on your phone
|
| 76 |
+
2. Open **Acceleration (without g)** and **Gyroscope**: record simultaneously
|
| 77 |
3. Hold the phone at your waist (same position as the UCI dataset)
|
| 78 |
4. Record at least 3 seconds of a single activity
|
| 79 |
5. Export both experiments as CSV and upload below
|
|
|
|
| 135 |
)
|
| 136 |
else:
|
| 137 |
st.warning(
|
| 138 |
+
"norm_params.json not found: features are in physical units. "
|
| 139 |
"Predictions will be unreliable until normalisation is applied."
|
| 140 |
)
|
| 141 |
|
| 142 |
# ββ Predictions βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 143 |
if ffn_status != "ready" and cnn_status != "ready":
|
| 144 |
+
st.warning("Models not loaded: cannot predict yet.")
|
| 145 |
return
|
| 146 |
|
| 147 |
st.markdown("---")
|
|
|
|
| 153 |
with col:
|
| 154 |
st.markdown(f"#### {name}")
|
| 155 |
if status != "ready":
|
| 156 |
+
st.error(f"Model not loaded: {status}")
|
| 157 |
return
|
| 158 |
|
| 159 |
probs_all = model.predict(features, verbose=0) # (n_windows, 6)
|
src/streamlit_app.py
CHANGED
|
@@ -21,12 +21,12 @@ LABEL_MAP = {
|
|
| 21 |
}
|
| 22 |
|
| 23 |
EXPLANATIONS = {
|
| 24 |
-
"LAYING": "Minimal movement detected across all axes with low acceleration magnitude
|
| 25 |
"SITTING": "Low dynamic acceleration with a stable gravity component suggests a stationary upright posture with little body movement.",
|
| 26 |
"STANDING": "Similar to sitting but with slight postural micro-movements. This class is often the hardest to distinguish from sitting.",
|
| 27 |
-
"WALKING": "Rhythmic periodic acceleration with peaks on the vertical axis
|
| 28 |
"WALKING_DOWNSTAIRS": "Downward gravitational shift with higher impact peaks characteristic of descending a staircase.",
|
| 29 |
-
"WALKING_UPSTAIRS": "Elevated vertical acceleration effort with upward body displacement
|
| 30 |
}
|
| 31 |
|
| 32 |
# ββ Model loader ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -84,11 +84,11 @@ with st.sidebar:
|
|
| 84 |
st.markdown("---")
|
| 85 |
st.markdown("**Models**")
|
| 86 |
st.markdown("""
|
| 87 |
-
**FFN**
|
| 88 |
Dense(512) β Dense(256) β Dense(128)
|
| 89 |
BatchNorm + Dropout(0.3) per layer
|
| 90 |
|
| 91 |
-
**CNN**
|
| 92 |
Conv1D(64) β Conv1D(128) β Conv1D(256)
|
| 93 |
GlobalAvgPool β Dense(128)
|
| 94 |
""")
|
|
@@ -102,9 +102,9 @@ cnn_model, cnn_status = load_model("har_cnn.keras")
|
|
| 102 |
|
| 103 |
if ffn_status != "ready" or cnn_status != "ready":
|
| 104 |
if ffn_status != "ready":
|
| 105 |
-
st.warning(f"FFN not loaded
|
| 106 |
if cnn_status != "ready":
|
| 107 |
-
st.warning(f"CNN not loaded
|
| 108 |
|
| 109 |
# ββ Tabs βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 110 |
|
|
@@ -124,7 +124,7 @@ with tab1:
|
|
| 124 |
feature_cols = [c for c in samples_df.columns if c not in ["Activity", "subject"]]
|
| 125 |
|
| 126 |
sample_labels = [
|
| 127 |
-
f"Sample {i+1}
|
| 128 |
for i, (_, row) in enumerate(samples_df.iterrows())
|
| 129 |
]
|
| 130 |
|
|
@@ -142,7 +142,7 @@ with tab1:
|
|
| 142 |
|
| 143 |
if st.button("Classify this sample", type="primary"):
|
| 144 |
if ffn_status != "ready" or cnn_status != "ready":
|
| 145 |
-
st.error("One or both models not loaded
|
| 146 |
else:
|
| 147 |
arr = feature_vector.reshape(1, -1)
|
| 148 |
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
EXPLANATIONS = {
|
| 24 |
+
"LAYING": "Minimal movement detected across all axes with low acceleration magnitude: consistent with a stationary horizontal posture.",
|
| 25 |
"SITTING": "Low dynamic acceleration with a stable gravity component suggests a stationary upright posture with little body movement.",
|
| 26 |
"STANDING": "Similar to sitting but with slight postural micro-movements. This class is often the hardest to distinguish from sitting.",
|
| 27 |
+
"WALKING": "Rhythmic periodic acceleration with peaks on the vertical axis: consistent with level walking at normal cadence.",
|
| 28 |
"WALKING_DOWNSTAIRS": "Downward gravitational shift with higher impact peaks characteristic of descending a staircase.",
|
| 29 |
+
"WALKING_UPSTAIRS": "Elevated vertical acceleration effort with upward body displacement: consistent with climbing stairs.",
|
| 30 |
}
|
| 31 |
|
| 32 |
# ββ Model loader ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 84 |
st.markdown("---")
|
| 85 |
st.markdown("**Models**")
|
| 86 |
st.markdown("""
|
| 87 |
+
**FFN**: Feedforward Network
|
| 88 |
Dense(512) β Dense(256) β Dense(128)
|
| 89 |
BatchNorm + Dropout(0.3) per layer
|
| 90 |
|
| 91 |
+
**CNN**: 1D Convolutional Network
|
| 92 |
Conv1D(64) β Conv1D(128) β Conv1D(256)
|
| 93 |
GlobalAvgPool β Dense(128)
|
| 94 |
""")
|
|
|
|
| 102 |
|
| 103 |
if ffn_status != "ready" or cnn_status != "ready":
|
| 104 |
if ffn_status != "ready":
|
| 105 |
+
st.warning(f"FFN not loaded: {ffn_status}")
|
| 106 |
if cnn_status != "ready":
|
| 107 |
+
st.warning(f"CNN not loaded: {cnn_status}")
|
| 108 |
|
| 109 |
# ββ Tabs βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 110 |
|
|
|
|
| 124 |
feature_cols = [c for c in samples_df.columns if c not in ["Activity", "subject"]]
|
| 125 |
|
| 126 |
sample_labels = [
|
| 127 |
+
f"Sample {i+1} : {row['Activity']}"
|
| 128 |
for i, (_, row) in enumerate(samples_df.iterrows())
|
| 129 |
]
|
| 130 |
|
|
|
|
| 142 |
|
| 143 |
if st.button("Classify this sample", type="primary"):
|
| 144 |
if ffn_status != "ready" or cnn_status != "ready":
|
| 145 |
+
st.error("One or both models not loaded: cannot predict yet.")
|
| 146 |
else:
|
| 147 |
arr = feature_vector.reshape(1, -1)
|
| 148 |
|