File size: 711 Bytes
2b0a350
95c7232
2b0a350
95c7232
 
 
 
2b0a350
95c7232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
import pickle

categories = ['Telecaster', 'Stratocaster', 'Jazzmaster']
examples = ['stratocaster.jpt', 'telecaster.jpg', 'jazzmaster.jpg']
image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()

# Load the trained model from the model.pkl file
with open("model.pkl", "rb") as f:
    model = pickle.load(f)


def predict(image):
    # image = cv2.resize(image, (224, 224))
    # image = np.expand_dims(image, axis=0)
    prediction, idx, probabilities = model.predict(image)
    return dict(zip(categories, map(float, probabilities)))


iface = gr.Interface(fn=predict, inputs=image, outputs=label,
                     examples=examples, capture_session=True)
iface.launch()