hb-setosys commited on
Commit
8d28437
·
verified ·
1 Parent(s): db196df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+
5
+ # Load the Keras model
6
+ model = tf.keras.models.load_model("denis_mnist_cnn_model.h5")
7
+
8
+ # Define a function to preprocess input and make predictions
9
+ def predict(image):
10
+ # Preprocess the image (resize, normalize, etc.)
11
+ image = tf.image.resize(image, (224, 224)) # Example: Resize to 224x224
12
+ image = np.expand_dims(image, axis=0) # Add batch dimension
13
+ image = image / 255.0 # Normalize pixel values
14
+
15
+ # Perform prediction
16
+ prediction = model.predict(image)
17
+ return {"prediction": prediction.tolist()}
18
+
19
+
20
+ # Create a Gradio interface
21
+ interface = gr.Interface(
22
+ fn=predict,
23
+ inputs="image", # Text input for comma-separated values
24
+ outputs="json" # JSON output for prediction results
25
+ )
26
+
27
+ # Launch the Gradio app
28
+ if __name__ == "__main__":
29
+ interface.launch()