Spaces:
Runtime error
Runtime error
import gradio as gr | |
import numpy as np | |
import pandas as pd | |
from tensorflow.keras import models | |
import tensorflow as tf | |
# open categories.txt in read mode | |
categories = open("categories.txt", "r") | |
labels = categories.readline().split(";") | |
model = models.load_model('models/modelnet/best_model.h5') | |
def predict_image(image): | |
image = np.array(image) / 255 | |
image = np.expand_dims(image, axis=0) | |
pred = model.predict(image) | |
acc = dict((labels[i], "%.2f" % pred[0][i]) for i in range(len(labels))) | |
print(acc) | |
return acc | |
image = gr.inputs.Image(shape=(224, 224), label="Upload Your Image Here") | |
label = gr.outputs.Label(num_top_classes=len(labels)) | |
samples = ['samples/basking.jpg', 'samples/blacktip.jpg', 'samples/blue.jpg', 'samples/bull.jpg', 'samples/hammerhead.jpg', | |
'samples/lemon.jpg', 'samples/mako.jpg', 'samples/nurse.jpg', 'samples/sand tiger.jpg', 'samples/thresher.jpg', | |
'samples/tigre.jpg', 'samples/whale.jpg', 'samples/white.jpg', 'samples/whitetip.jpg'] | |
interface = gr.Interface( | |
fn=predict_image, | |
inputs=image, | |
outputs=label, | |
capture_session=True, | |
allow_flagging=False, | |
examples=samples | |
) | |
interface.launch() |