Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from age_estimator.mivolo.demo_copy import main as age_estimation_main
|
4 |
+
|
5 |
+
def process_age_estimation(video_file):
|
6 |
+
# Validate the input file path
|
7 |
+
if not video_file or not os.path.isfile(video_file):
|
8 |
+
return {'error': 'Invalid video path'}
|
9 |
+
|
10 |
+
# Define parameters for age estimation
|
11 |
+
output_folder = 'output'
|
12 |
+
detector_weights = 'age_estimator/mivolo/models/yolov8x_person_face.pt'
|
13 |
+
checkpoint = 'age_estimator/mivolo/models/model_imdb_cross_person_4.22_99.46.pth.tar'
|
14 |
+
device = 'cpu'
|
15 |
+
with_persons = True
|
16 |
+
disable_faces = False
|
17 |
+
draw = True
|
18 |
+
|
19 |
+
# Run age estimation
|
20 |
+
absolute_age, lower_bound, upper_bound = age_estimation_main(
|
21 |
+
video_file, output_folder, detector_weights, checkpoint, device, with_persons, disable_faces, draw
|
22 |
+
)
|
23 |
+
|
24 |
+
# Compile results
|
25 |
+
results = {
|
26 |
+
'Age Range': f"{lower_bound} - {upper_bound}"
|
27 |
+
}
|
28 |
+
|
29 |
+
return results
|
30 |
+
|
31 |
+
# Define Gradio interface for Age Estimation
|
32 |
+
gr.Interface(
|
33 |
+
fn=process_age_estimation,
|
34 |
+
inputs=gr.Video(label="Upload a video file"),
|
35 |
+
outputs="json",
|
36 |
+
title="Age Estimation"
|
37 |
+
).launch(server_name="0.0.0.0")
|