File size: 862 Bytes
8d28437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
import tensorflow as tf
import numpy as np

# Load the Keras model
model = tf.keras.models.load_model("denis_mnist_cnn_model.h5")

# Define a function to preprocess input and make predictions
def predict(image):
    # Preprocess the image (resize, normalize, etc.)
    image = tf.image.resize(image, (224, 224))  # Example: Resize to 224x224
    image = np.expand_dims(image, axis=0)  # Add batch dimension
    image = image / 255.0  # Normalize pixel values

    # Perform prediction
    prediction = model.predict(image)
    return {"prediction": prediction.tolist()}
    

# Create a Gradio interface
interface = gr.Interface(
    fn=predict, 
    inputs="image",  # Text input for comma-separated values
    outputs="json"  # JSON output for prediction results
)

# Launch the Gradio app
if __name__ == "__main__":
    interface.launch()