musakhan10 commited on
Commit
fb3239d
·
verified ·
1 Parent(s): 1a5eb85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -7,12 +7,14 @@ MODEL_PATH = "activity_model.keras"
7
  CLASS_NAMES = ["Stationary", "Walking", "Running"]
8
  EXPECTED_STEPS = 100
9
 
10
- model = tf.keras.models.load_model("activity_model.keras")
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)
@@ -21,8 +23,10 @@ def read_signal(file_path):
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):
@@ -38,6 +42,7 @@ with gr.Blocks() as demo:
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,
 
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
+
16
  df = pd.read_csv(file_path)
17
+
18
  # Accept either a column named sensor_value or the first numeric column.
19
  if "sensor_value" in df.columns:
20
  values = df["sensor_value"].to_numpy(dtype=np.float32)
 
23
  if numeric.shape[1] == 0:
24
  raise gr.Error("CSV must contain a numeric sensor column.")
25
  values = numeric.iloc[:, 0].to_numpy(dtype=np.float32)
26
+
27
  if len(values) != EXPECTED_STEPS:
28
  raise gr.Error(f"Expected exactly {EXPECTED_STEPS} sensor readings, found {len(values)}.")
29
+
30
  return values
31
 
32
  def predict_activity(file_path):
 
42
  output = gr.Label(label="Prediction", num_top_classes=3)
43
  button = gr.Button("Predict activity", variant="primary")
44
  button.click(predict_activity, inputs=file_input, outputs=output)
45
+
46
  gr.Examples(
47
  examples=[["sample_stationary.csv"], ["sample_walking.csv"], ["sample_running.csv"]],
48
  inputs=file_input,