Spaces:
Sleeping
Sleeping
File size: 857 Bytes
acc2d02 df9ee76 a64e68a acc2d02 a64e68a acc2d02 |
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 31 |
import torch
import torchvision
import torch.nn as nn
model = torchvision.models.resnet50(pretrained=False)
model.fc = nn.Linear(model.fc.in_features, num_classes)
model.load_state_dict(torch.load("model.pth"))
model.to(device)
model.eval()
import gradio as gr
from PIL import Image
# Define the function to make predictions
def predict(image):
image = transform(image).unsqueeze(0).to(device)
model.eval()
with torch.no_grad():
output = model(image)
_, predicted = torch.max(output.data, 1)
return dataset.classes[predicted.item()]
# Define the input and output components
image_input = gr.inputs.Image(type="pil", label="Upload Image")
label_output = gr.outputs.Label()
# Create the interface
interface = gr.Interface(fn=predict, inputs=image_input, outputs=label_output)
# Launch the interface
interface.launch() |