anasazasaa commited on
Commit
df24eff
1 Parent(s): 1b43d24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -27
app.py CHANGED
@@ -102,30 +102,26 @@ def predict(image, model, face_detector, device, margin=0.4, input_size=224):
102
  return image
103
 
104
 
105
- device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
106
- model = load_model(device)
107
- face_detector = dlib.get_frontal_face_detector()
108
- fn = functools.partial(predict,
109
- model=model,
110
- face_detector=face_detector,
111
- device=device)
112
-
113
- image_dir = pathlib.Path('sample_images')
114
- examples = [path.as_posix() for path in sorted(image_dir.glob('*.jpg'))]
115
-
116
- with gr.Interface(css='style.css') as demo:
117
- gr.Markdown(DESCRIPTION)
118
- with gr.Row():
119
- with gr.Column():
120
- image = gr.Image(label='Input', type='filepath')
121
- run_button = gr.Button('Run')
122
- with gr.Column():
123
- result = gr.Image(label='Result')
124
-
125
- gr.Examples(examples=examples,
126
- inputs=image,
127
- outputs=result,
128
- fn=fn,
129
- cache_examples=os.getenv('CACHE_EXAMPLES') == '1')
130
- run_button.click(fn=fn, inputs=image, outputs=result, api_name='predict')
131
- demo.queue(max_size=15).launch()
 
102
  return image
103
 
104
 
105
+ def main():
106
+ device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
107
+ model = load_model(device)
108
+ face_detector = dlib.get_frontal_face_detector()
109
+ fn = functools.partial(predict, model=model, face_detector=face_detector, device=device)
110
+
111
+ image_dir = pathlib.Path('sample_images')
112
+ examples = [path.as_posix() for path in sorted(image_dir.glob('*.jpg'))]
113
+
114
+ demo = gr.Interface(
115
+ fn=fn,
116
+ inputs=gr.inputs.Image(type="filepath"),
117
+ outputs="image",
118
+ examples=examples,
119
+ title="Age Estimation",
120
+ description=DESCRIPTION,
121
+ cache_examples=os.getenv('CACHE_EXAMPLES') == '1'
122
+ )
123
+
124
+ demo.launch()
125
+
126
+ if __name__ == '__main__':
127
+ main()