Rishiharan commited on
Commit
aa72760
·
verified ·
1 Parent(s): d4b3741

Upload 2 files

Browse files

This is a Image classifier Models that Helps to CLassify the Clothes

Files changed (2) hide show
  1. app.py +41 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from transformers import CLIPProcessor, CLIPModel
4
+ from PIL import Image
5
+ import torch, requests
6
+ from io import BytesIO
7
+ import numpy as np
8
+
9
+ # Load CLIP model
10
+ model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
11
+ processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
12
+
13
+ labels = [
14
+ "dress or gown",
15
+ "t-shirt or top or blouse",
16
+ "jeans or pants or trousers",
17
+ "shoes or sneakers or boots",
18
+ "jacket or coat or blazer",
19
+ "handbag or purse or bag",
20
+ "accessories or jewelry",
21
+ "sportswear or activewear",
22
+ "formal wear or suit",
23
+ "non-fashion item"
24
+ ]
25
+
26
+ def classify(img):
27
+ inputs = processor(text=labels, images=img, return_tensors="pt", padding=True)
28
+ outputs = model(**inputs)
29
+ probs = outputs.logits_per_image.softmax(dim=1)[0].detach().numpy()
30
+ result = {labels[i]: float(probs[i]) for i in range(len(labels))}
31
+ return result
32
+
33
+ iface = gr.Interface(
34
+ fn=classify,
35
+ inputs=gr.Image(type="pil"),
36
+ outputs=gr.Label(num_top_classes=3),
37
+ title="AI Clothing Classifier",
38
+ description="Upload an image to identify clothing or fashion items."
39
+ )
40
+
41
+ iface.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+
2
+ gradio
3
+ torch
4
+ transformers
5
+ Pillow
6
+ requests