File size: 783 Bytes
2b0a350
920dca5
 
 
 
 
 
 
 
 
 
2b0a350
95c7232
 
2b0a350
95c7232
920dca5
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
25
26
27
28
29
30
import gradio as gr
from fastai.vision.all import *
import os

# list all file names in the samples directory
examples = []
for file in os.listdir('samples'):
    examples.append(['samples/' + file])

categories = ['Jazzmaster', 'Stratocaster', 'Telecaster']


image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()

# Load the trained model from the model.pkl file
model = load_learner('model.pkl')


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()