SegevC commited on
Commit
485a795
1 Parent(s): 231fa06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -16
app.py CHANGED
@@ -12,8 +12,6 @@ def get_x(data_set):
12
  def get_y(data_set):
13
  return data_set['bf_est']
14
 
15
-
16
-
17
  def new_splitter(df):
18
  # Get the unique values in the 'id' column
19
  unique_ids = df['id'].unique()
@@ -37,22 +35,55 @@ def new_splitter(df):
37
  return test, valid
38
 
39
  title = "Body Fat Predictor"
40
- description = "A Body Fat Predictor trained on the subreddit \"guessmybf\"."
41
- article = "for best preformence upload a front facing photo"
 
 
 
 
 
 
 
42
 
43
  learner = load_learner("bf_model.pkl")
44
 
45
- def predict_bf(img):
46
- # pil_img = PILImage.create(img)
47
- return round(float(learner.predict(img)[1]),2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- image = gr.Image(shape=(192,192))
50
- # label = gr.float()
51
- intf = gr.Interface(fn =predict_bf, inputs = image, outputs = "number", title=title, description=description, article=article)
52
- intf.launch(inline= False)
53
 
54
- # def greet(name):
55
- # return "Hello " + name + "!!" + "This is version 2!!!"
56
-
57
- # iface = gr.Interface(fn=greet, inputs="text", outputs="text")
58
- # iface.launch()
 
12
  def get_y(data_set):
13
  return data_set['bf_est']
14
 
 
 
15
  def new_splitter(df):
16
  # Get the unique values in the 'id' column
17
  unique_ids = df['id'].unique()
 
35
  return test, valid
36
 
37
  title = "Body Fat Predictor"
38
+ description = "A Body Fat Predictor trained on the subreddit \"guessmybf\". \
39
+ For best preformence upload a front facing photo. \n The Range button allows \
40
+ you to adjust the range of the predicted body fat percentage. \
41
+ Choosing a higher range results in a less specific prediction but a more ecurate estimate, \
42
+ while a lower range provides a less precise estimate. \n The Examples section \
43
+ provides visual examples of different body fat percentages and how they appear \
44
+ on an individual's body. It is important to note that two individuals can have \
45
+ the same body fat percentage but look different due to differences in body composition \
46
+ (such as muscle mass)."
47
 
48
  learner = load_learner("bf_model.pkl")
49
 
50
+ # def predict_bf(img):
51
+ # return round(float(learner.predict(img)[1]),2)
52
+
53
+ def predict_bf(img, range=0):
54
+ if range not in [0,1,2,3,4]:
55
+ range = 1
56
+ prediction = math.floor(float(learner.predict(img)[1]))
57
+ if range ==0:
58
+ return f"{str(prediction)}%"
59
+ else:
60
+ return f"{str(round(prediction) - range)}-{str(round(prediction) + range)}%"
61
+
62
+
63
+ examples=[
64
+ ['/exp/6-8.jpg', '6-8'],
65
+ ['/exp/7-9.jpg', '7-9'],
66
+ ['/exp/9-11.jpg', '9-11'],
67
+ ['/exp/9-11v2.jpg', '9-11'],
68
+ ['/exp/10-12.jpg', '10-12'],
69
+ ['/exp/10-12v2.jpg', '10-12'],
70
+ ['/exp/11-13.jpg', '11-13'],
71
+ ['/exp/13-15.jpg', '13-15'],
72
+ ['/exp/13-15v2.jpg', '13-15'],
73
+ ['/exp/15-17.jpg', '15-17'],
74
+ ['/exp/15-17v2.jpg', '15-17'],
75
+ ['/exp/15-17v3.jpg', '15-17'],
76
+ ['/exp/17-19.jpg', '17-19'],
77
+ ['/exp/19-20.jpg', '19-20'],
78
+ ['/exp/19-20v2.jpg', '19-20'],
79
+ ['/exp/21-23.jpg', '21-23'],
80
+ ['/exp/22-24.jpg', '22-24'],
81
+ ['/exp/23-25.jpg', '23-25'],
82
+ ['/exp/24-26.jpg', '24-26']
83
+ ]
84
 
 
 
 
 
85
 
86
+ image = gr.Image(shape=(192,192))
87
+ intf = gr.Interface(fn =predict_bf, inputs = [image, gr.Radio([0,1,2,3,4])], outputs = gr.outputs.Textbox(),
88
+ title = title, description = description, examples=examples)
89
+ intf.launch(inline= True)