PrachiY commited on
Commit
d73d036
·
verified ·
1 Parent(s): a38b574

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -41
app.py DELETED
@@ -1,41 +0,0 @@
1
- import torch
2
- import torchvision.transforms as transforms
3
- import gradio as gr
4
- from PIL import Image
5
-
6
- # Load a Pretrained Fashion Classification Model (ResNet18)
7
- model = torch.hub.load('pytorch/vision:v0.10.0', 'resnet18', pretrained=True)
8
- model.eval() # Set model to evaluation mode
9
-
10
- # Define Class Labels for Clothing Items
11
- class_labels = [
12
- "T-shirt", "Shirt", "Sweater", "Dress", "Jacket",
13
- "Coat", "Pants", "Shorts", "Skirt", "Jeans"
14
- ]
15
-
16
- # Image Preprocessing
17
- transform = transforms.Compose([
18
- transforms.Resize((224, 224)), # Resize image
19
- transforms.ToTensor(), # Convert to tensor
20
- transforms.Normalize(mean=[0.485, 0.456, 0.406],
21
- std=[0.229, 0.224, 0.225]) # Normalize
22
- ])
23
-
24
- # Classification Function
25
- def classify_dress(image):
26
- image = transform(image).unsqueeze(0) # Add batch dimension
27
- with torch.no_grad():
28
- output = model(image) # Run through model
29
- predicted_class_index = output.argmax(dim=1).item()
30
- return class_labels[predicted_class_index]
31
-
32
- # Gradio Interface
33
- iface = gr.Interface(
34
- fn=classify_dress,
35
- inputs=gr.Image(type="pil"),
36
- outputs=gr.Label(num_top_classes=3),
37
- title="Clothing1M Classifier",
38
- description="Upload an image of clothing to classify it into one of 10 categories."
39
- )
40
-
41
- iface.launch()