import gradio as gr import numpy as np import cv2 from PIL import Image from PIFuHD.data import EvalWMetaDataset from PIFuHD.data.ImageBundle import ImageBundle from PIFuHD.options import BaseOptions from PIFuHD.recontructor import Reconstructor from huggingface_hub import hf_hub_download from human_pose_estimator import PoseEstimator from estimator import rect REPO_ID = "cxeep/PIFuHD" pose_estimator = PoseEstimator("cpu") checkpoint_path = hf_hub_download(repo_id=REPO_ID, filename="pifuhd.pt") cmd = [ '--dataroot', './data', '--results_path', './results', '--loadSize', '1024', '--resolution', '256', '--load_netMR_checkpoint_path', checkpoint_path, '--start_id', '-1', '--end_id', '-1' ] parser = BaseOptions() opts = parser.parse(cmd) reconstructor = Reconstructor(opts) def make_bundle(image, name): image, rects = rect(pose_estimator, image) return ImageBundle(img=image, name=name, meta=rects) def process_video(video_path): frames = [] cap = cv2.VideoCapture(video_path) while cap.isOpened(): ret, frame = cap.read() if not ret: break frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) frames.append(Image.fromarray(frame)) cap.release() models = [] for frame in frames: bundle = make_bundle(np.array(frame), "Model3D") dataset = EvalWMetaDataset(opts, [bundle]) model = reconstructor.evaluate(dataset) models.append(model) # TODO: Combine models into animation output_animation = models[0] # Placeholder, replace with actual animation return output_animation def predict(input_img, input_video): if input_video: return process_video(input_video) elif input_img is not None: bundle = make_bundle(input_img, "Model3D") dataset = EvalWMetaDataset(opts, [bundle]) return reconstructor.evaluate(dataset) else: return None, None footer = r""" """ with gr.Blocks(title="PIFuHD") as app: gr.HTML("