prithivMLmods commited on
Commit
f2b1774
·
verified ·
1 Parent(s): 3987e62

Delete age_classification.py

Browse files
Files changed (1) hide show
  1. age_classification.py +0 -47
age_classification.py DELETED
@@ -1,47 +0,0 @@
1
- import gradio as gr
2
- import spaces
3
- from transformers import AutoImageProcessor
4
- from transformers import SiglipForImageClassification
5
- from transformers.image_utils import load_image
6
- from PIL import Image
7
- import torch
8
-
9
- # Load model and processor
10
- model_name = "prithivMLmods/Age-Classification-SigLIP2"
11
- model = SiglipForImageClassification.from_pretrained(model_name)
12
- processor = AutoImageProcessor.from_pretrained(model_name)
13
-
14
- @spaces.GPU
15
- def age_classification(image):
16
- """Predicts the age group of a person from an image."""
17
- image = Image.fromarray(image).convert("RGB")
18
- inputs = processor(images=image, return_tensors="pt")
19
-
20
- with torch.no_grad():
21
- outputs = model(**inputs)
22
- logits = outputs.logits
23
- probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
24
-
25
- labels = {
26
- "0": "Child 0-12",
27
- "1": "Teenager 13-20",
28
- "2": "Adult 21-44",
29
- "3": "Middle Age 45-64",
30
- "4": "Aged 65+"
31
- }
32
- predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
33
-
34
- return predictions
35
-
36
- # Create Gradio interface
37
- iface = gr.Interface(
38
- fn=age_classification,
39
- inputs=gr.Image(type="numpy"),
40
- outputs=gr.Label(label="Prediction Scores"),
41
- title="Age Group Classification",
42
- description="Upload an image to predict the person's age group."
43
- )
44
-
45
- # Launch the app
46
- if __name__ == "__main__":
47
- iface.launch()