File size: 1,237 Bytes
0e1d66c
 
 
 
1a45e9e
 
9bc890f
1a45e9e
 
 
9bc890f
1a45e9e
 
4a00854
1a45e9e
 
 
 
 
 
 
 
0e1d66c
1a45e9e
 
 
 
 
 
 
 
edb703c
1a45e9e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gradio as gr
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
from sklearn.preprocessing import StandardScaler
import pandas as pd

# Load model and label encoder
model = load_model("human_activity_recognition_model.h5")
label_encoder = {0: "Walking", 1: "Running", 2: "Jumping", 3: "Sitting"}  # Adjust as per your dataset

# Sample scaler (ensure this matches what you used during training)
scaler = StandardScaler()

# Define prediction function
def predict_activity(x, y, z):
    sample_input = np.array([[x, y, z]])
    sample_input = scaler.fit_transform(sample_input)  # Apply the same scaling as training
    sample_input = np.expand_dims(sample_input, axis=0)  # Reshape for LSTM input
    prediction = model.predict(sample_input)
    predicted_label = label_encoder[np.argmax(prediction)]
    return f"Predicted Activity: {predicted_label}"

# Create Gradio Interface
demo = gr.Interface(
    fn=predict_activity,
    inputs=[gr.Number(label="X-axis"), gr.Number(label="Y-axis"), gr.Number(label="Z-axis")],
    outputs="text",
    title="Human Activity Recognition",
    description="Enter accelerometer values (X, Y, Z) to predict activity.",
)

# Launch the app
demo.launch()