Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import numpy as np
|
2 |
-
|
3 |
import gradio as gr
|
4 |
|
5 |
-
# Load the saved
|
6 |
-
|
|
|
7 |
|
8 |
# Define action mapping
|
9 |
action_map = {
|
@@ -18,50 +19,41 @@ action_map = {
|
|
18 |
# Function to process inputs and get a prediction
|
19 |
def action(e1, e2, e3, e4, e5, e6, e7, e8):
|
20 |
# Duplicate each value 3 times to create a 24-length input
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
predicted_class = np.argmax(prediction, axis=-1)
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
[-2.00e-05, 1.00e-05, 2.20e-04, 1.80e-04, -1.50e-04, -5.00e-05, 1.00e-05, 0],
|
51 |
-
[1.60e-04, -1.00e-04, -2.40e-04, 2.00e-04, 1.00e-04, -9.00e-05, -5.00e-05, -5.00e-05],
|
52 |
-
[-1.00e-05, 1.00e-05, 1.00e-05, 0, -2.00e-05, 0, -3.00e-05, -3.00e-05],
|
53 |
-
]
|
54 |
-
|
55 |
-
# Gradio interface
|
56 |
-
iface = gr.Interface(
|
57 |
-
fn=action,
|
58 |
-
inputs=inputs,
|
59 |
-
outputs=output,
|
60 |
-
title="ML Model Predictor",
|
61 |
-
examples=examples,
|
62 |
-
flagging_options=["Working", "Not Working"],
|
63 |
-
description="Enter the 8 feature values to get a prediction."
|
64 |
-
)
|
65 |
|
66 |
# Launch Gradio UI
|
67 |
iface.launch(share=True, debug=True)
|
|
|
1 |
import numpy as np
|
2 |
+
import pickle
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# Load the saved pickle model
|
6 |
+
with open('model8346.pkl', 'rb') as f:
|
7 |
+
model = pickle.load(f)
|
8 |
|
9 |
# Define action mapping
|
10 |
action_map = {
|
|
|
19 |
# Function to process inputs and get a prediction
|
20 |
def action(e1, e2, e3, e4, e5, e6, e7, e8):
|
21 |
# Duplicate each value 3 times to create a 24-length input
|
22 |
+
input_data_reshaped = np.array(input_data).reshape(1, -1)
|
23 |
+
predicted_label = loaded_model.predict(input_data_reshaped)[0]
|
24 |
+
return action_map.get(predicted_class[0], "Unknown action")
|
25 |
+
|
26 |
+
# Define Gradio UI with improved styling
|
27 |
+
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
28 |
+
gr.Markdown("""
|
29 |
+
# π€ ML Model Predictor
|
30 |
+
### Enter the 8 feature values below to get a prediction
|
31 |
+
""")
|
32 |
|
33 |
+
with gr.Row():
|
34 |
+
inputs = [gr.Number(label=f"Feature {i+1}", interactive=True) for i in range(8)]
|
35 |
|
36 |
+
output = gr.Textbox(label="Prediction", interactive=False)
|
|
|
37 |
|
38 |
+
submit_btn = gr.Button("π Predict")
|
39 |
+
submit_btn.click(action, inputs=inputs, outputs=output)
|
40 |
+
|
41 |
+
gr.Examples(
|
42 |
+
examples=[
|
43 |
+
[-2.00e-05, 1.00e-05, 2.20e-04, 1.80e-04, -1.50e-04, -5.00e-05, 1.00e-05, 0],
|
44 |
+
[1.60e-04, -1.00e-04, -2.40e-04, 2.00e-04, 1.00e-04, -9.00e-05, -5.00e-05, -5.00e-05],
|
45 |
+
[-1.00e-05, 1.00e-05, 1.00e-05, 0, -2.00e-05, 0, -3.00e-05, -3.00e-05],
|
46 |
+
],
|
47 |
+
inputs=inputs,
|
48 |
+
label="Try with Example Inputs"
|
49 |
+
)
|
50 |
+
|
51 |
+
gr.Markdown("""
|
52 |
+
### π How it Works:
|
53 |
+
- Enter values for the 8 features.
|
54 |
+
- Click the **Predict** button.
|
55 |
+
- The model will analyze the input and classify the hand motion.
|
56 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
# Launch Gradio UI
|
59 |
iface.launch(share=True, debug=True)
|