| import numpy as np |
| import pickle |
| import gradio as gr |
|
|
| |
| with open('model-r.pkl', 'rb') as f: |
| model = pickle.load(f) |
|
|
| |
| 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", |
| } |
|
|
| |
| def action(e1, e2, e3, e4, e5, e6, e7, e8): |
| |
| 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") |
|
|
| |
| 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. |
| """) |
|
|
| |
| iface.launch(share=True, debug=True) |
|
|