imabackstabber commited on
Commit
3a34d98
1 Parent(s): bc30f4c

test frontend

Browse files
Files changed (4) hide show
  1. app.py +121 -4
  2. assets/01.jpg +0 -0
  3. assets/02.jpg +0 -0
  4. assets/03.jpg +0 -0
app.py CHANGED
@@ -1,7 +1,124 @@
 
 
 
 
 
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import os.path as osp
4
+ from pathlib import Path
5
+ import cv2
6
  import gradio as gr
7
+ import torch
8
+ import math
9
+ import spaces
10
 
11
+ try:
12
+ import mmpose
13
+ except:
14
+ os.system('pip install /home/user/app/main/transformer_utils')
15
 
16
+ os.system('cp -rf /home/user/app/assets/conversions.py /home/user/.pyenv/versions/3.9.18/lib/python3.9/site-packages/torchgeometry/core/conversions.py')
17
+ DEFAULT_MODEL='smpler_x_h32'
18
+ OUT_FOLDER = '/home/user/app/demo_out'
19
+ os.makedirs(OUT_FOLDER, exist_ok=True)
20
+ # num_gpus = 1 if torch.cuda.is_available() else -1
21
+ # print("!!!", torch.cuda.is_available())
22
+ # print(torch.cuda.device_count())
23
+ # print(torch.version.cuda)
24
+ # index = torch.cuda.current_device()
25
+ # print(index)
26
+ # print(torch.cuda.get_device_name(index))
27
+ # from main.inference import Inferer
28
+ # inferer = Inferer(DEFAULT_MODEL, num_gpus, OUT_FOLDER)
29
+
30
+ @spaces.GPU(enable_queue=True)
31
+ def infer(image_input, in_threshold=0.5, num_people="Single person", render_mesh=False):
32
+ # num_gpus = 1 if torch.cuda.is_available() else -1
33
+ # print("!!!", torch.cuda.is_available())
34
+ # print(torch.cuda.device_count())
35
+ # print(torch.version.cuda)
36
+ # index = torch.cuda.current_device()
37
+ # print(index)
38
+ # print(torch.cuda.get_device_name(index))
39
+ # from main.inference import Inferer
40
+ # inferer = Inferer(DEFAULT_MODEL, num_gpus, OUT_FOLDER)
41
+ # os.system(f'rm -rf {OUT_FOLDER}/*')
42
+ # multi_person = False if (num_people == "Single person") else True
43
+ # cap = cv2.VideoCapture(video_input)
44
+ # fps = math.ceil(cap.get(5))
45
+ # width = int(cap.get(3))
46
+ # height = int(cap.get(4))
47
+ # fourcc = cv2.VideoWriter_fourcc(*'mp4v')
48
+ # video_path = osp.join(OUT_FOLDER, f'out.m4v')
49
+ # final_video_path = osp.join(OUT_FOLDER, f'out.mp4')
50
+ # video_output = cv2.VideoWriter(video_path, fourcc, fps, (width, height))
51
+ # success = 1
52
+ # frame = 0
53
+ # while success:
54
+ # success, original_img = cap.read()
55
+ # if not success:
56
+ # break
57
+ # frame += 1
58
+ # img, mesh_paths, smplx_paths = inferer.infer(original_img, in_threshold, frame, multi_person, not(render_mesh))
59
+ # video_output.write(img)
60
+ # yield img, None, None, None
61
+ # cap.release()
62
+ # video_output.release()
63
+ # cv2.destroyAllWindows()
64
+ # os.system(f'ffmpeg -i {video_path} -c copy {final_video_path}')
65
+
66
+ # #Compress mesh and smplx files
67
+ # save_path_mesh = os.path.join(OUT_FOLDER, 'mesh')
68
+ # save_mesh_file = os.path.join(OUT_FOLDER, 'mesh.zip')
69
+ # os.makedirs(save_path_mesh, exist_ok= True)
70
+ # save_path_smplx = os.path.join(OUT_FOLDER, 'smplx')
71
+ # save_smplx_file = os.path.join(OUT_FOLDER, 'smplx.zip')
72
+ # os.makedirs(save_path_smplx, exist_ok= True)
73
+ # os.system(f'zip -r {save_mesh_file} {save_path_mesh}')
74
+ # os.system(f'zip -r {save_smplx_file} {save_path_smplx}')
75
+ # yield img, video_path, save_mesh_file, save_smplx_file
76
+ return image_input, "success"
77
+
78
+ TITLE = '''<h1 align="center">PostoMETRO: Pose Token Enhanced Mesh Transformer for Robust 3D Human Mesh Recovery</h1>'''
79
+ DESCRIPTION = '''
80
+ <b>Official Gradio demo</b> for <b>PostoMETRO: Pose Token Enhanced Mesh Transformer for Robust 3D Human Mesh Recovery</b>.<br>
81
+ <p>
82
+ Note: You can drop a image at the panel (or select one of the examples)
83
+ to obtain the 3D parametric reconstructions of the detected humans.
84
+ </p>
85
+ '''
86
+
87
+ with gr.Blocks(title="PostoMETRO", css=".gradio-container") as demo:
88
+
89
+ gr.Markdown(TITLE)
90
+ gr.Markdown(DESCRIPTION)
91
+
92
+ with gr.Row():
93
+ with gr.Column():
94
+ image_input = gr.Image(label="Input image", elem_classes="Image")
95
+ threshold = gr.Slider(0, 1.0, value=0.5, label='BBox detection threshold')
96
+ num_people = gr.Radio(
97
+ choices=["Single person", "Multiple people"],
98
+ value="Single person",
99
+ label="Number of people",
100
+ info="Choose how many people are there in the video. Choose 'single person' for faster inference.",
101
+ interactive=True,
102
+ scale=1,)
103
+ mesh_as_vertices = gr.Checkbox(
104
+ label="Render as mesh",
105
+ info="By default, the estimated SMPL-X parameters are rendered as vertices for faster visualization. Check this option if you want to visualize meshes instead.",
106
+ interactive=True,
107
+ scale=1,)
108
+ send_button = gr.Button("Infer")
109
+ with gr.Column():
110
+ processed_frames = gr.Image(label="Last processed frame")
111
+ debug_textbox = gr.Textbox(label="Debug information")
112
+
113
+ # example_images = gr.Examples([])
114
+ send_button.click(fn=infer, inputs=[image_input, threshold, num_people, mesh_as_vertices], outputs=[processed_frames, debug_textbox])
115
+ # with gr.Row():
116
+ example_images = gr.Examples([
117
+ ['/home/user/app/assets/01.jpg'],
118
+ ['/home/user/app/assets/02.jpg'],
119
+ ['/home/user/app/assets/03.jpg'],
120
+ ],
121
+ inputs=[image_input, 0.5])
122
+
123
+ #demo.queue()
124
+ demo.queue().launch(debug=True)
assets/01.jpg ADDED
assets/02.jpg ADDED
assets/03.jpg ADDED