Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,27 @@
|
|
| 1 |
-
# temporary_app.py
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
return "Hello, " + name + "!"
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|