Spaces:
Sleeping
Sleeping
anasazasaa
commited on
Commit
•
df24eff
1
Parent(s):
1b43d24
Update app.py
Browse files
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 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
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()
|
|
|
|
|
|
|
|