jervinjosh68 commited on
Commit
2fe1bcc
1 Parent(s): 0173331

added app.py and requirements.txt

Browse files
Files changed (6) hide show
  1. app.py +51 -0
  2. baby.jpg +0 -0
  3. gob remm.png +0 -0
  4. gradio_queue.db +0 -0
  5. requirements.txt +5 -0
  6. surprisa.jpg +0 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import gradio as gr
3
+ from transformers import ViTFeatureExtractor, ViTForImageClassification
4
+ import torch
5
+
6
+ # Init model, transforms
7
+ model = ViTForImageClassification.from_pretrained('nateraw/vit-age-classifier')
8
+ transforms = ViTFeatureExtractor.from_pretrained('nateraw/vit-age-classifier')
9
+
10
+ def predict(im):
11
+ labels = {0:"0-2", 1: "3-9" , 2: "10-19", 3: "20-29", 4: "30-39", 5: "40-49", 6: "50-59"}
12
+ # Transform our image and pass it through the model
13
+ inputs = transforms(im, return_tensors='pt')
14
+ output = model(**inputs)
15
+
16
+ # Predicted Class probabilities
17
+ proba = output.logits.softmax(1)
18
+
19
+ # Predicted Classes
20
+ preds = proba.argmax(1)
21
+ values, indices = torch.topk(proba, k=5)
22
+ result = zip(indices, values)
23
+
24
+
25
+ return {labels[i.item()]: v.item() for i, v in zip(indices.numpy()[0], values.detach().numpy()[0])}
26
+
27
+
28
+ print(predict(Image.open("baby.jpg")))
29
+
30
+
31
+ inputs = [
32
+ gr.inputs.Image(type="pil", label="Original Image")
33
+ ]
34
+
35
+
36
+
37
+ title = "Vit-Age-Classification"
38
+ description = "ViT-Age-Classification is used to categorize an individual's age using images"
39
+ article = " <a href='https://huggingface.co/nateraw/vit-age-classifier'>Model Repo on Hugging Face Model Hub</a>"
40
+ examples = ["surprisa.png"]
41
+
42
+ gr.Interface(
43
+ predict,
44
+ inputs,
45
+ outputs = 'label',
46
+ title=title,
47
+ description=description,
48
+ article=article,
49
+ examples=examples,
50
+ theme="huggingface",
51
+ ).launch(debug=True, enable_queue=True)
baby.jpg ADDED
gob remm.png ADDED
gradio_queue.db ADDED
Binary file (229 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ gradio
3
+ requests
4
+ Pillow
5
+ torch
surprisa.jpg ADDED