andrewwwwwwww commited on
Commit
fcfc40d
·
verified ·
1 Parent(s): e73e8af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,9 +1,27 @@
1
- # temporary_app.py
2
  import gradio as gr
 
3
 
4
- def greet(name):
5
- return "Hello, " + name + "!"
6
 
7
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  iface.launch()
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ MODEL_AGE = pipeline('image-classification', model='nateraw/vit-age-classifier', device=-1)
 
5
 
6
+ def predict(image):
7
+ age_result = MODEL_AGE(image)
8
+ top_age = age_result[0]['label']
9
+ age_map = {
10
+ "3-9": 6,
11
+ "10-19": 15,
12
+ "20-29": 25,
13
+ "30-39": 35,
14
+ "40-49": 45,
15
+ "50-59": 55,
16
+ "60-69": 65,
17
+ "more than 70": 75
18
+ }
19
+ return {"data": [age_map.get(top_age, 30)]}
20
+
21
+ iface = gr.Interface(
22
+ fn=predict,
23
+ inputs=gr.Image(type="pil"),
24
+ outputs=gr.Json()
25
+ )
26
 
27
  iface.launch()