Spaces:
Paused
Paused
Julian Bilcke commited on
Commit ·
22b2a6e
1
Parent(s): d96ce03
improve concurrency
Browse filesFiles changed (3)
78 unmodified lines7980818283848578 unmodified lineselif msg.type == WSMsgType.TEXT:data = json.loads(msg.data)webp_bytes = engine.transform_image(data.get('hash'), data.get('params'))await ws.send_bytes(webp_bytes)except Exception as e:78 unmodified lines7980818283848578 unmodified lineselif msg.type == WSMsgType.TEXT:data = json.loads(msg.data)webp_bytes = await engine.transform_image(data.get('hash'), data.get('params'))await ws.send_bytes(webp_bytes)except Exception as e:
17 unmodified lines1819202122232417 unmodified lines// if we only send the face/square then we can use 138ms// unfortunately it doesn't work well yet// const throttleInMs = 138msconst throttleInMs = 200////////////////////////////////////////////////////////////////////////// State for face detection17 unmodified lines1819202122232417 unmodified lines// if we only send the face/square then we can use 138ms// unfortunately it doesn't work well yet// const throttleInMs = 138msconst throttleInMs = 220////////////////////////////////////////////////////////////////////////// State for face detection
128 unmodified lines12913013113213313413561 unmodified lines1971981992002012022032042052062076 unmodified lines214215216217218219220221222223224128 unmodified lines# 'bbox_rot': bbox_info['bbox_rot'].toList(), # 4x2}def transform_image(self, image_hash: str, params: Dict[str, float]) -> bytes:# If we don't have the image in cache yet, add itif image_hash not in self.processed_cache:raise ValueError("cache miss")61 unmodified linesx_d_new = processed_data['x_s_info']['scale'] * (x_d_new @ R_new) + processed_data['x_s_info']['t']# Apply stitchingx_d_new = self.live_portrait.live_portrait_wrapper.stitching(processed_data['x_s'], x_d_new)# Generate the outputout = self.live_portrait.live_portrait_wrapper.warp_decode(processed_data['f_s'], processed_data['x_s'], x_d_new)I_p = self.live_portrait.live_portrait_wrapper.parse_output(out['out'])buffered = io.BytesIO()6 unmodified lines# I'm currently running some experiments to do it in the frontend## --- old way: we do it in the server-side: ---mask_ori = prepare_paste_back(processed_data['inference_cfg'].mask_crop, processed_data['crop_info']['M_c2o'],dsize=(processed_data['img_rgb'].shape[1], processed_data['img_rgb'].shape[0]))I_p_to_ori_blend = paste_back(I_p[0], processed_data['crop_info']['M_c2o'], processed_data['img_rgb'], mask_ori)result_image = Image.fromarray(I_p_to_ori_blend)128 unmodified lines12913013113213313413561 unmodified lines1971981992002012022032042052062076 unmodified lines214215216217218219220221222223224128 unmodified lines# 'bbox_rot': bbox_info['bbox_rot'].toList(), # 4x2}async def transform_image(self, image_hash: str, params: Dict[str, float]) -> bytes:# If we don't have the image in cache yet, add itif image_hash not in self.processed_cache:raise ValueError("cache miss")61 unmodified linesx_d_new = processed_data['x_s_info']['scale'] * (x_d_new @ R_new) + processed_data['x_s_info']['t']# Apply stitchingx_d_new = await asyncio.to_thread(self.live_portrait.live_portrait_wrapper.stitching, processed_data['x_s'], x_d_new)# Generate the outputout = await asyncio.to_thread(self.live_portrait.live_portrait_wrapper.warp_decode, processed_data['f_s'], processed_data['x_s'], x_d_new)I_p = await asyncio.to_thread(self.live_portrait.live_portrait_wrapper.parse_output, out['out'])buffered = io.BytesIO()6 unmodified lines# I'm currently running some experiments to do it in the frontend## --- old way: we do it in the server-side: ---mask_ori = await asyncio.to_thread(prepare_paste_back,processed_data['inference_cfg'].mask_crop, processed_data['crop_info']['M_c2o'],dsize=(processed_data['img_rgb'].shape[1], processed_data['img_rgb'].shape[0]))I_p_to_ori_blend = await asyncio.to_thread(paste_back,I_p[0], processed_data['crop_info']['M_c2o'], processed_data['img_rgb'], mask_ori)result_image = Image.fromarray(I_p_to_ori_blend)
app.py+1-1
client/src/hooks/useFaceLandmarkDetection.tsx+1-1
engine.py+6-6