File size: 776 Bytes
9ddcbad
 
 
 
 
 
8b03506
9ddcbad
 
 
 
 
 
 
 
 
 
b27e7fb
9ddcbad
 
b27e7fb
 
 
 
9ddcbad
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
import tensorflow as tf
import gradio as gr
import numpy as np
from PIL import Image

# Load the model
model = tf.saved_model.load('.')

# Define the prediction function
def predict(image):
    # Preprocess the image to the required input format
    img = np.array(image).astype(np.float32)
    img = np.expand_dims(img, axis=0)  # Add batch dimension
    img = tf.image.resize(img, (640, 640))  # Resize if needed

    # Perform inference
    predictions = model(img)
    return predictions.numpy().tolist()  # Adjust output processing as needed

# Set up the Gradio interface
image_input = gr.inputs.Image(shape=(640, 640))
label_output = gr.outputs.Label(num_top_classes=3)

interface = gr.Interface(fn=predict, inputs=image_input, outputs=label_output)
interface.launch()