Update model.py
Browse files
model.py
CHANGED
@@ -31,4 +31,37 @@ class AgeGenderViTModel(ViTPreTrainedModel):
|
|
31 |
gender_output = self.gender_head(pooled_output)
|
32 |
|
33 |
logits = torch.cat([age_output, gender_output], dim=1)
|
34 |
-
return {"logits": logits}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
gender_output = self.gender_head(pooled_output)
|
32 |
|
33 |
logits = torch.cat([age_output, gender_output], dim=1)
|
34 |
+
return {"logits": logits}
|
35 |
+
|
36 |
+
# Add this to the END of your model.py file
|
37 |
+
|
38 |
+
def predict_age_gender(image_path):
|
39 |
+
"""
|
40 |
+
Simple one-liner function for age-gender prediction
|
41 |
+
|
42 |
+
Args:
|
43 |
+
image_path: Path to image file or URL
|
44 |
+
|
45 |
+
Returns:
|
46 |
+
Dictionary with age, gender, confidence
|
47 |
+
"""
|
48 |
+
from transformers import pipeline
|
49 |
+
|
50 |
+
classifier = pipeline("image-classification", model="abhilash88/age-gender-prediction", trust_remote_code=True)
|
51 |
+
raw = classifier(image_path)
|
52 |
+
result = raw[0] # Get first result
|
53 |
+
|
54 |
+
return {
|
55 |
+
'age': result['age'],
|
56 |
+
'gender': result['gender'],
|
57 |
+
'confidence': result['gender_confidence'],
|
58 |
+
'summary': f"{result['age']} years, {result['gender']} ({result['gender_confidence']:.1%} confidence)"
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
def simple_predict(image_path):
|
63 |
+
"""
|
64 |
+
Even simpler - just returns a string
|
65 |
+
"""
|
66 |
+
result = predict_age_gender(image_path)
|
67 |
+
return result['summary']
|