Pengi5659 commited on
Commit
8f89e6c
·
verified ·
1 Parent(s): 9f7c7d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -4,10 +4,10 @@ import torchvision.transforms as transforms
4
  import torchvision.models as models
5
  from PIL import Image
6
 
7
- # Load the ResNet18 model with pre-trained weights
8
  model = models.resnet18(weights=models.ResNet18_Weights.IMAGENET1K_V1)
9
  model.fc = torch.nn.Linear(model.fc.in_features, 2) # Adjust for two classes
10
- model.eval() # Set to evaluation mode
11
 
12
  # Define image transformation
13
  transform = transforms.Compose([
@@ -25,6 +25,6 @@ def classify_image(image):
25
  _, predicted = torch.max(output, 1)
26
  return "Good Posture" if predicted.item() == 0 else "Bad Posture"
27
 
28
- # Set up Gradio interface for webcam or image upload
29
- iface = gr.Interface(fn=classify_image, inputs=gr.Image(type="pil", source="upload"), outputs="text")
30
  iface.launch()
 
4
  import torchvision.models as models
5
  from PIL import Image
6
 
7
+ # Load ResNet18 model
8
  model = models.resnet18(weights=models.ResNet18_Weights.IMAGENET1K_V1)
9
  model.fc = torch.nn.Linear(model.fc.in_features, 2) # Adjust for two classes
10
+ model.eval()
11
 
12
  # Define image transformation
13
  transform = transforms.Compose([
 
25
  _, predicted = torch.max(output, 1)
26
  return "Good Posture" if predicted.item() == 0 else "Bad Posture"
27
 
28
+ # Set up Gradio interface
29
+ iface = gr.Interface(fn=classify_image, inputs=gr.Image(type="pil"), outputs="text")
30
  iface.launch()