import torch model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval() import requests import PIL from torchvision import transforms # Download human-readable labels for ImageNet. response = requests.get("https://git.io/JJkYN") labels = response.text.split("\n") def classify_image(image_filepath): PIL_image = PIL.Image.open(image_filepath).convert('RGB') transformations = transforms.Compose([ transforms.Resize(size = (224,224)), transforms.ToTensor(), ]) image_tensors = transformations(PIL_image).unsqueeze(0) with torch.no_grad(): prediction = torch.nn.functional.softmax(model(image_tensors)[0], dim=0) confidences = {labels[i]: float(prediction[i]) for i in range(1000)} return confidences import gradio as gr with gr.Blocks(title="Image Classification for 1000 Objects", css=".gradio-container {background:mintcream;}") as demo: gr.HTML("""