Upload 3 files
Browse files- app.py +35 -0
- iris_mlp.weights.h5 +3 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
|
6 |
+
model_path = "iris_mlp.weights.h5"
|
7 |
+
model = tf.keras.Sequential([
|
8 |
+
tf.keras.layers.InputLayer(input_shape=[4]),
|
9 |
+
tf.keras.layers.BatchNormalization(),
|
10 |
+
tf.keras.layers.Dense(32, activation="relu"),
|
11 |
+
tf.keras.layers.Dense(16, activation="relu"),
|
12 |
+
tf.keras.layers.Dense(3, activation="softmax")
|
13 |
+
])
|
14 |
+
model.load_weights(model_path)
|
15 |
+
|
16 |
+
labels = ['Setosa', 'Versicolour', 'Virginica']
|
17 |
+
|
18 |
+
# Define the core prediction function
|
19 |
+
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
|
20 |
+
features = [sepal_length, sepal_width, petal_length, petal_width]
|
21 |
+
features = np.array(features)[None, ...]
|
22 |
+
prediction = model.predict(features)
|
23 |
+
print(prediction)
|
24 |
+
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
25 |
+
return confidences
|
26 |
+
|
27 |
+
# Create the Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=predict_iris,
|
30 |
+
inputs=["number", "number", "number", "number"],
|
31 |
+
outputs=gr.Label(),
|
32 |
+
examples=[[7.7, 2.6, 6.9, 2.3]]
|
33 |
+
)
|
34 |
+
|
35 |
+
iface.launch()
|
iris_mlp.weights.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a4dd6c3813f72c9a26f660bfd898100dd26d4ed68a803cad7063361c5a5dc726
|
3 |
+
size 33792
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tensorflow
|