Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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",
|
9 |
+
3: "Wrist flexion",
|
10 |
+
4: "Wrist extension",
|
11 |
+
5: "Radial deviations",
|
12 |
+
6: "Ulnar deviations",
|
13 |
+
}
|
14 |
+
|
15 |
+
def action(e1, e2, e3, e4, e5, e6, e7, e8):
|
16 |
+
input_data = np.array([[e1, e2, e3, e4, e5, e6, e7, e8]])
|
17 |
+
prediction = model.predict(input_data)
|
18 |
+
predicted_class = np.argmax(prediction, axis=-1)
|
19 |
+
return action_map.get(predicted_class[0]+1, "Unknown action")
|
20 |
+
|
21 |
+
inputs = [
|
22 |
+
gr.Number(label="e1"),
|
23 |
+
gr.Number(label="e2"),
|
24 |
+
gr.Number(label="e3"),
|
25 |
+
gr.Number(label="e4"),
|
26 |
+
gr.Number(label="e5"),
|
27 |
+
gr.Number(label="e6"),
|
28 |
+
gr.Number(label="e7"),
|
29 |
+
gr.Number(label="e8"),
|
30 |
+
]
|
31 |
+
|
32 |
+
output = gr.Textbox(label="Prediction")
|
33 |
+
|
34 |
+
def func(e1, e2, e3, e4, e5, e6, e7, e8):
|
35 |
+
return action(e1, e2, e3, e4, e5, e6, e7, e8)
|
36 |
+
|
37 |
+
iface = gr.Interface(
|
38 |
+
fn=func,
|
39 |
+
inputs=inputs,
|
40 |
+
outputs=output,
|
41 |
+
title="ML Model Predictor",
|
42 |
+
description="Enter the 8 feature values to get a prediction."
|
43 |
+
)
|
44 |
+
|
45 |
+
iface.launch()
|