Spaces:
Runtime error
Runtime error
Upload 7 files
Browse files- DL_Group_Lab_Starter.ipynb +0 -0
- README.md +12 -6
- app.py +47 -0
- requirements.txt +4 -0
- wearable_activity_test.csv +0 -0
- wearable_activity_train.csv +0 -0
- wearable_activity_validation.csv +0 -0
DL_Group_Lab_Starter.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
CHANGED
|
@@ -1,13 +1,19 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: ๐
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 6.26.0
|
| 8 |
-
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Wearable Activity Classifier
|
| 3 |
emoji: ๐
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: gradio
|
|
|
|
|
|
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Wearable Activity Classifier
|
| 12 |
+
|
| 13 |
+
Beginner Deep Learning group-lab demo. The Space loads a student-trained Keras model and classifies a CSV of 100 sensor readings into Stationary, Walking, or Running.
|
| 14 |
+
|
| 15 |
+
## Required files
|
| 16 |
+
Upload `activity_model.keras` from the completed notebook together with `app.py`, `requirements.txt`, and the sample CSV files.
|
| 17 |
+
|
| 18 |
+
## Educational note
|
| 19 |
+
The training data are synthetic and intentionally simple. This demo is for learning model architecture and deployment workflow, not real-world activity recognition.
|
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
|
| 6 |
+
MODEL_PATH = "activity_model.keras"
|
| 7 |
+
CLASS_NAMES = ["Stationary", "Walking", "Running"]
|
| 8 |
+
EXPECTED_STEPS = 100
|
| 9 |
+
|
| 10 |
+
model = tf.keras.models.load_model(MODEL_PATH)
|
| 11 |
+
|
| 12 |
+
def read_signal(file_path):
|
| 13 |
+
if file_path is None:
|
| 14 |
+
raise gr.Error("Please upload a CSV file.")
|
| 15 |
+
df = pd.read_csv(file_path)
|
| 16 |
+
# Accept either a column named sensor_value or the first numeric column.
|
| 17 |
+
if "sensor_value" in df.columns:
|
| 18 |
+
values = df["sensor_value"].to_numpy(dtype=np.float32)
|
| 19 |
+
else:
|
| 20 |
+
numeric = df.select_dtypes(include=["number"])
|
| 21 |
+
if numeric.shape[1] == 0:
|
| 22 |
+
raise gr.Error("CSV must contain a numeric sensor column.")
|
| 23 |
+
values = numeric.iloc[:, 0].to_numpy(dtype=np.float32)
|
| 24 |
+
if len(values) != EXPECTED_STEPS:
|
| 25 |
+
raise gr.Error(f"Expected exactly {EXPECTED_STEPS} sensor readings, found {len(values)}.")
|
| 26 |
+
return values
|
| 27 |
+
|
| 28 |
+
def predict_activity(file_path):
|
| 29 |
+
values = read_signal(file_path)
|
| 30 |
+
x = values.reshape(1, EXPECTED_STEPS, 1)
|
| 31 |
+
probs = model.predict(x, verbose=0)[0]
|
| 32 |
+
return {name: float(prob) for name, prob in zip(CLASS_NAMES, probs)}
|
| 33 |
+
|
| 34 |
+
with gr.Blocks() as demo:
|
| 35 |
+
gr.Markdown("# Wearable Activity Classifier")
|
| 36 |
+
gr.Markdown("Upload a CSV containing exactly 100 sensor readings. The student-trained model predicts Stationary, Walking, or Running.")
|
| 37 |
+
file_input = gr.File(label="Sensor CSV", file_types=[".csv"], type="filepath")
|
| 38 |
+
output = gr.Label(label="Prediction", num_top_classes=3)
|
| 39 |
+
button = gr.Button("Predict activity", variant="primary")
|
| 40 |
+
button.click(predict_activity, inputs=file_input, outputs=output)
|
| 41 |
+
gr.Examples(
|
| 42 |
+
examples=[["sample_stationary.csv"], ["sample_walking.csv"], ["sample_running.csv"]],
|
| 43 |
+
inputs=file_input,
|
| 44 |
+
label="Sample files"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow-cpu>=2.16,<3
|
| 2 |
+
pandas>=2.0
|
| 3 |
+
numpy>=1.26
|
| 4 |
+
gradio>=5,<7
|
wearable_activity_test.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
wearable_activity_train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
wearable_activity_validation.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|