File size: 908 Bytes
9f7c7d5
1d7ddcf
 
 
 
bb53c2f
8f89e6c
46d545a
 
8f89e6c
46d545a
 
1d7ddcf
 
 
 
bb53c2f
46d545a
1d7ddcf
61677f5
a6f0837
61677f5
1d7ddcf
 
 
a6f0837
1d7ddcf
a6f0837
d32de0a
dfa9fe7
a6f0837
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
import gradio as gr
import torch
import torchvision.transforms as transforms
import torchvision.models as models
from PIL import Image

# Load ResNet18 model
model = models.resnet18(weights=models.ResNet18_Weights.IMAGENET1K_V1)
model.fc = torch.nn.Linear(model.fc.in_features, 2)  # Adjust for two classes
model.eval()

# Define image transformation
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor()
])

# Function to classify posture images
def classify_image(image):
    if image is None:
        return "No image provided!"
    
    image = transform(image).unsqueeze(0)
    output = model(image)
    _, predicted = torch.max(output, 1)
    return "Good Posture" if predicted.item() == 0 else "Bad Posture"

# Set up Gradio interface with live webcam capture
iface = gr.Interface(fn=classify_image, inputs=gr.Image(type="pil"), outputs="text")
iface.launch()