Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,25 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
import os
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
print('Issue with image:', image_path)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import torchvision.transforms as transforms
|
| 4 |
+
import torchvision.models as models
|
| 5 |
+
from PIL import Image
|
| 6 |
|
| 7 |
+
# Load model (ensure it's uploaded to the Space)
|
| 8 |
+
model = models.resnet18(pretrained=True)
|
| 9 |
+
model.fc = torch.nn.Linear(model.fc.in_features, 2) # Adjust for your classes
|
|
|
|
| 10 |
|
| 11 |
+
transform = transforms.Compose([
|
| 12 |
+
transforms.Resize((224, 224)),
|
| 13 |
+
transforms.ToTensor()
|
| 14 |
+
])
|
| 15 |
|
| 16 |
+
# Define the function to classify images
|
| 17 |
+
def classify_image(image):
|
| 18 |
+
image = transform(image).unsqueeze(0)
|
| 19 |
+
output = model(image)
|
| 20 |
+
_, predicted = torch.max(output, 1)
|
| 21 |
+
return "Class_A" if predicted.item() == 0 else "Class_B"
|
| 22 |
+
|
| 23 |
+
# Set up Gradio interface
|
| 24 |
+
iface = gr.Interface(fn=classify_image, inputs="webcam", outputs="text")
|
| 25 |
+
iface.launch()
|
|
|