Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
-
import pandas as pd
|
2 |
import numpy as np
|
3 |
from tensorflow.keras.models import load_model
|
4 |
import gradio as gr
|
5 |
|
|
|
|
|
|
|
|
|
6 |
action_map = {
|
7 |
1: "Hand at rest",
|
8 |
2: "Hand clenched in a fist",
|
@@ -12,13 +15,22 @@ action_map = {
|
|
12 |
6: "Ulnar deviations",
|
13 |
}
|
14 |
|
|
|
15 |
def action(e1, e2, e3, e4, e5, e6, e7, e8):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
|
|
22 |
inputs = [
|
23 |
gr.Number(label="e1"),
|
24 |
gr.Number(label="e2"),
|
@@ -30,26 +42,26 @@ inputs = [
|
|
30 |
gr.Number(label="e8"),
|
31 |
]
|
32 |
|
|
|
33 |
output = gr.Textbox(label="Prediction")
|
34 |
|
|
|
35 |
examples = [
|
36 |
[-2.00e-05, 1.00e-05, 2.20e-04, 1.80e-04, -1.50e-04, -5.00e-05, 1.00e-05, 0],
|
37 |
[1.60e-04, -1.00e-04, -2.40e-04, 2.00e-04, 1.00e-04, -9.00e-05, -5.00e-05, -5.00e-05],
|
38 |
[-1.00e-05, 1.00e-05, 1.00e-05, 0, -2.00e-05, 0, -3.00e-05, -3.00e-05],
|
39 |
]
|
40 |
|
41 |
-
|
42 |
-
return action(e1, e2, e3, e4, e5, e6, e7, e8)
|
43 |
-
|
44 |
iface = gr.Interface(
|
45 |
-
fn=
|
46 |
inputs=inputs,
|
47 |
outputs=output,
|
48 |
title="ML Model Predictor",
|
49 |
examples=examples,
|
50 |
-
flagging_options=["Working", "Not
|
51 |
description="Enter the 8 feature values to get a prediction."
|
52 |
)
|
53 |
|
54 |
-
#
|
55 |
-
iface.launch(share=True)
|
|
|
|
|
1 |
import numpy as np
|
2 |
from tensorflow.keras.models import load_model
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# Load the saved .h5 model
|
6 |
+
model = load_model('model8346.h5')
|
7 |
+
|
8 |
+
# Define action mapping
|
9 |
action_map = {
|
10 |
1: "Hand at rest",
|
11 |
2: "Hand clenched in a fist",
|
|
|
15 |
6: "Ulnar deviations",
|
16 |
}
|
17 |
|
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 |
+
input_data = np.array([[e1, e1, e1, e2, e2, e2, e3, e3, e3,
|
22 |
+
e4, e4, e4, e5, e5, e5, e6, e6, e6,
|
23 |
+
e7, e7, e7, e8, e8, e8]])
|
24 |
+
|
25 |
+
# Get model prediction
|
26 |
+
prediction = model.predict(input_data)
|
27 |
+
|
28 |
+
# Get predicted class
|
29 |
+
predicted_class = np.argmax(prediction, axis=-1)
|
30 |
+
|
31 |
+
return action_map.get(predicted_class[0] + 1, "Unknown action")
|
32 |
|
33 |
+
# Define Gradio inputs
|
34 |
inputs = [
|
35 |
gr.Number(label="e1"),
|
36 |
gr.Number(label="e2"),
|
|
|
42 |
gr.Number(label="e8"),
|
43 |
]
|
44 |
|
45 |
+
# Define Gradio output
|
46 |
output = gr.Textbox(label="Prediction")
|
47 |
|
48 |
+
# Example inputs (same as before)
|
49 |
examples = [
|
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)
|