File size: 925 Bytes
33d6349
 
 
 
 
 
 
29ed669
ad03cdd
 
 
37ee4dc
3906d80
 
29ed669
 
ad03cdd
37ee4dc
29ed669
acc2d02
29ed669
 
37ee4dc
ad03cdd
 
 
acc2d02
29ed669
 
 
acc2d02
29ed669
acc2d02
92d7df2
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
32
33
34
import gradio as gr
import torch
from torchvision.transforms import ToTensor
from torchvision.models import resnet50
from PIL import Image
import torch.nn as nn

# Load your PyTorch model
model = resnet50(pretrained=False)
model.fc = nn.Linear(model.fc.in_features, 2)
model.load_state_dict(torch.load("model.pth", map_location=torch.device('cpu')))

classes = ['bom', 'ruim']

# Define the function for image classification
def classify_image(image):
    image_tensor = ToTensor()(image).unsqueeze(0)

    # Perform inference using your PyTorch model
    with torch.no_grad():
        model.eval()
        outputs = model(image_tensor)

        _, predicted = torch.max(outputs.data, 1)
        return classes[predicted.item()]


# Define the Gradio interface
inputs = gr.Image()
outputs = gr.Label(num_top_classes=1)

interface = gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs)

interface.launch(debug=True)