Spaces:
Build error
Build error
Download Classification.py from karthik45456e/phi2: direct link, hf CLI and curl.
- Browser
- Download file 870 Bytes
-
https://huggingface.co/spaces/karthik45456e/phi2/resolve/main/Classification.py
- Command line
-
hf download hf://spaces/karthik45456e/phi2/Classification.py
-
curl -L -o Classification.py https://huggingface.co/spaces/karthik45456e/phi2/resolve/main/Classification.py
870 Bytes
| from PIL import Image | |
| import requests | |
| from transformers import CLIPProcessor, CLIPModel | |
| def classife(img): | |
| model = CLIPModel.from_pretrained("openai/clip-vit-large-patch14") | |
| processor = CLIPProcessor.from_pretrained("openai/clip-vit-large-patch14") | |
| image = Image.open(img) | |
| inputs = processor(text=["Health Person", "Weak Person","Fat person"], images=image, return_tensors="pt", padding=True) | |
| outputs = model(**inputs) | |
| logits_per_image = outputs.logits_per_image # this is the image-text similarity score | |
| probs = logits_per_image.softmax(dim=1) | |
| labels = ["Health", "weak","fat"] | |
| predicted_label = labels[probs.argmax()] | |
| return predicted_label | |
| # url = "https://c8.alamy.com/comp/GJ4Y4H/very-obese-man-GJ4Y4H.jpg" | |
| # img = requests.get(url, stream=True).raw | |
| # probabilities = classif(img) | |
| # print(f"Probabilities: {probabilities}") |