kuhs commited on
Commit
503c7ba
1 Parent(s): 4806972

Upload 7 files

Browse files
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load your custom regression model
7
+ model_path = "kia_mnist_keras_model.weights.h5"
8
+ model = tf.keras.Sequential([
9
+ tf.keras.layers.Flatten(input_shape=[28, 28]),
10
+ tf.keras.layers.Rescaling(1./255.),
11
+ tf.keras.layers.Dense(300, activation="relu"),
12
+ tf.keras.layers.Dense(100, activation="relu"),
13
+ tf.keras.layers.Dense(10, activation="softmax")
14
+ ])
15
+ model.load_weights(model_path)
16
+
17
+ labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
18
+
19
+ # Define regression function
20
+ def predict_regression(image):
21
+ # Preprocess image
22
+ image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
23
+ image = image.resize((28, 28)).convert('L') #resize the image to 28x28 and converts it to gray scale
24
+ image = np.array(image)
25
+ print(image.shape)
26
+ # Predict
27
+ prediction = model.predict(image[None, ...]) # Assuming single regression value
28
+ confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
29
+ return confidences
30
+
31
+ # Create Gradio interface
32
+ input_image = gr.Image()
33
+ output_text = gr.Textbox(label="Predicted Value")
34
+ interface = gr.Interface(fn=predict_regression,
35
+ inputs=input_image,
36
+ outputs=gr.Label(),
37
+ examples=["images/0.jpeg", "images/1.jpeg", "images/2.jpeg", "images/5.jpeg"],
38
+ description="A custom regression model for image regression using .h5 file.")
39
+ interface.launch()
images/0.jpeg ADDED
images/1.jpeg ADDED
images/2.jpeg ADDED
images/5.jpeg ADDED
kia_mnist_keras_model.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:93d2db3e726864243d6c83cbd9039aaf671b564ec141f51c2bff674ff67faae6
3
+ size 3220912
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tensorflow