Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import torchvision.transforms as transforms
|
| 4 |
import torchvision.models as models
|
|
@@ -17,11 +17,14 @@ transform = transforms.Compose([
|
|
| 17 |
|
| 18 |
# Function to classify posture images
|
| 19 |
def classify_image(image):
|
|
|
|
|
|
|
|
|
|
| 20 |
image = transform(image).unsqueeze(0)
|
| 21 |
output = model(image)
|
| 22 |
_, predicted = torch.max(output, 1)
|
| 23 |
return "Good Posture" if predicted.item() == 0 else "Bad Posture"
|
| 24 |
|
| 25 |
# Set up Gradio interface for webcam or image upload
|
| 26 |
-
iface = gr.Interface(fn=classify_image, inputs=gr.Image(type="pil"), outputs="text")
|
| 27 |
iface.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import torchvision.transforms as transforms
|
| 4 |
import torchvision.models as models
|
|
|
|
| 17 |
|
| 18 |
# Function to classify posture images
|
| 19 |
def classify_image(image):
|
| 20 |
+
if image is None:
|
| 21 |
+
return "No image provided!"
|
| 22 |
+
|
| 23 |
image = transform(image).unsqueeze(0)
|
| 24 |
output = model(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()
|