File size: 1,082 Bytes
9eba1bb
 
 
 
 
 
 
 
 
 
 
 
 
59dcabc
9eba1bb
9fc4843
9eba1bb
 
165f545
5d55a00
9eba1bb
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from fastai.vision.all import *
import gradio as gr

def get_bmi(): return _
def get_age(): return _
def combine_loss(): return _
def age_loss(): return _
def bmi_loss(): return _

learn = load_learner("export.pkl")


def classify_image(img):
    tst_dl = learn.dls.test_dl([img], num_workers = 0)
    preds,_ = learn.get_preds(dl=tst_dl)
    result_text = "This person is " + str(round(preds[0][0].item(), 0)) + " years old with a BMI of " + str(round(preds[0][1].item(), 1)) + " kg/m^2"
    return result_text

image = gr.inputs.Image()
examples = ['A00147.png','K86344.png','A00360.png', "R89614.png", 'A01681.png', 'R79591.png','R86556.png', "R43263.png", 'Y15554.png', "X78069.png"]
title = 'Predict Age and Body Mass Index from a Picture'
description = 'This app predicts the age and BMI of a person just from their face.'
article = "Author: <a href=\"https://huggingface.co/archietram\">Archie Tram</a>. "

intf = gr.Interface(fn=classify_image, inputs=image, outputs="text", examples=examples, title=title, description=description, article=article)
intf.launch(inline=False)