File size: 1,870 Bytes
2104cd5
 
 
 
36039f6
 
 
 
2104cd5
 
 
 
 
 
 
 
 
36039f6
2104cd5
36039f6
 
 
 
 
 
 
 
 
 
 
 
2104cd5
36039f6
2104cd5
 
 
 
 
 
 
 
 
 
 
36039f6
2104cd5
 
36039f6
367a7ac
 
 
 
 
 
36039f6
2104cd5
36039f6
2104cd5
 
 
367a7ac
36039f6
2104cd5
 
 
36039f6
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
from tensorflow.keras.models import load_model
import gradio as gr

# Load the saved .h5 model
model = load_model('model8346.h5')

# Define action mapping
action_map = {
    1: "Hand at rest",
    2: "Hand clenched in a fist",
    3: "Wrist flexion",
    4: "Wrist extension",
    5: "Radial deviations",
    6: "Ulnar deviations",
}

# Function to process inputs and get a prediction
def action(e1, e2, e3, e4, e5, e6, e7, e8):
    # Duplicate each value 3 times to create a 24-length input
    input_data = np.array([[e1, e1, e1, e2, e2, e2, e3, e3, e3, 
                             e4, e4, e4, e5, e5, e5, e6, e6, e6, 
                             e7, e7, e7, e8, e8, e8]])
    
    # Get model prediction
    prediction = model.predict(input_data)
    
    # Get predicted class
    predicted_class = np.argmax(prediction, axis=-1)
    
    return action_map.get(predicted_class[0] + 1, "Unknown action")

# Define Gradio inputs
inputs = [
    gr.Number(label="e1"),
    gr.Number(label="e2"),
    gr.Number(label="e3"),
    gr.Number(label="e4"),
    gr.Number(label="e5"),
    gr.Number(label="e6"),
    gr.Number(label="e7"),
    gr.Number(label="e8"),
]

# Define Gradio output
output = gr.Textbox(label="Prediction")

# Example inputs (same as before)
examples = [
    [-2.00e-05, 1.00e-05, 2.20e-04, 1.80e-04, -1.50e-04, -5.00e-05, 1.00e-05, 0],
    [1.60e-04, -1.00e-04, -2.40e-04, 2.00e-04, 1.00e-04, -9.00e-05, -5.00e-05, -5.00e-05],
    [-1.00e-05, 1.00e-05, 1.00e-05, 0, -2.00e-05, 0, -3.00e-05, -3.00e-05],
]

# Gradio interface
iface = gr.Interface(
    fn=action,
    inputs=inputs,
    outputs=output,
    title="ML Model Predictor",
    examples=examples,
    flagging_options=["Working", "Not Working"],
    description="Enter the 8 feature values to get a prediction."
)

# Launch Gradio UI
iface.launch(share=True, debug=True)