Spaces:
Sleeping
Sleeping
Download app.py from Rishiharan/Dress_image_Classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/Rishiharan/Dress_image_Classifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rishiharan/Dress_image_Classifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rishiharan/Dress_image_Classifier/resolve/main/app.py
1.17 kB
| import gradio as gr | |
| from transformers import CLIPProcessor, CLIPModel | |
| from PIL import Image | |
| import torch, requests | |
| from io import BytesIO | |
| import numpy as np | |
| # Load CLIP model | |
| model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32") | |
| processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32") | |
| labels = [ | |
| "dress or gown", | |
| "t-shirt or top or blouse", | |
| "jeans or pants or trousers", | |
| "shoes or sneakers or boots", | |
| "jacket or coat or blazer", | |
| "handbag or purse or bag", | |
| "accessories or jewelry", | |
| "sportswear or activewear", | |
| "formal wear or suit", | |
| "non-fashion item" | |
| ] | |
| def classify(img): | |
| inputs = processor(text=labels, images=img, return_tensors="pt", padding=True) | |
| outputs = model(**inputs) | |
| probs = outputs.logits_per_image.softmax(dim=1)[0].detach().numpy() | |
| result = {labels[i]: float(probs[i]) for i in range(len(labels))} | |
| return result | |
| iface = gr.Interface( | |
| fn=classify, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Label(num_top_classes=3), | |
| title="AI Clothing Classifier", | |
| description="Upload an image to identify clothing or fashion items." | |
| ) | |
| iface.launch(share=True) | |