Spaces:
Runtime error
Runtime error
import torch | |
import gradio as gr | |
from torch import nn | |
from torch.nn import functional as F | |
import torchvision | |
from PIL import Image | |
from torchvision import transforms | |
transformer = transforms.Compose([ | |
transforms.ToPILImage(), | |
transforms.Resize((224, 224)), | |
transforms.ToTensor(), | |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) | |
]) | |
model_best=torch.jit.load('model_scriptedd.pt',map_location=torch.device('cpu')) | |
classes=['Good luck','Love','Ok','Thumb up','Victory'] | |
def predict(inp): | |
inp=transformer(inp).unsqueeze(0) | |
with torch.no_grad(): | |
prediction =F.softmax(model_best(inp)[0], dim=0) | |
confidences = {classes[i]: float(prediction[i]) for i in range(5)} | |
return confidences | |
gr.Interface(predict,inputs=gr.inputs.Image(label="Input Image"),outputs='label').launch(debug='True') | |
#gr.Interface(predict,inputs=[gr.inputs.Image(label="Input Image", source="webcam"),gr.inputs.Image(label="Input Image")],outputs='label').launch(debug='True') |