File size: 1,922 Bytes
2104cd5
a86506c
2104cd5
 
a86506c
fcb4400
a86506c
36039f6
 
2104cd5
6b55b91
2104cd5
 
 
 
 
 
 
 
36039f6
2104cd5
36039f6
3a738f7
 
ee07178
3e712fd
a86506c
 
 
 
 
 
 
36039f6
a86506c
 
36039f6
a86506c
36039f6
a86506c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import pickle
import gradio as gr

# Load the saved pickle model
with open('model-r.pkl', 'rb') as f:
    model = pickle.load(f)

# Define action mapping
action_map = {
    0: "CLASS0ACTION",
    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, e2, e3, e4, e5, e6, e7, e8])
    input_data_reshaped = input_data.reshape(1, -1)
    predicted_label = model.predict(input_data_reshaped)[0]
    return action_map.get(predicted_label, "Unknown action")

# Define Gradio UI with improved styling
with gr.Blocks(theme=gr.themes.Soft()) as iface:
    gr.Markdown("""
    # πŸ€– ML Model Predictor
    ### Enter the 8 feature values below to get a prediction
    """)
    
    with gr.Row():
        inputs = [gr.Number(label=f"Feature {i+1}", interactive=True) for i in range(8)]
    
    output = gr.Textbox(label="Prediction", interactive=False)
    
    submit_btn = gr.Button("πŸ” Predict")
    submit_btn.click(action, inputs=inputs, outputs=output)
    
    gr.Examples(
        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],
        ],
        inputs=inputs,
        label="Try with Example Inputs"
    )
    
    gr.Markdown("""
    ### πŸ” How it Works:
    - Enter values for the 8 features.
    - Click the **Predict** button.
    - The model will analyze the input and classify the hand motion.
    """)

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