Spaces:
Configuration error
Configuration error
Update
Browse filesFiles changed (10)
33 unmodified lines34353633 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text*.jpg filter=lfs diff=lfs merge=lfs -text33 unmodified lines3435363733 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text*.jpg filter=lfs diff=lfs merge=lfs -text*.mp4 filter=lfs diff=lfs merge=lfs -text
6 unmodified lines789101112131415161718192021227 unmodified lines3031323334353664 unmodified lines1011021031041051061071081091101111121131141151161171181191201211221231241251266 unmodified lines"""import pathlibimport gradio as grimport PIL.Imageimport spacesimport supervision as svimport torchfrom transformers import AutoProcessor, RTDetrForObjectDetection, VitPoseForPoseEstimationDESCRIPTION = "# ViTPose"device = torch.device("cuda" if torch.cuda.is_available() else "cpu")person_detector_name = "PekingU/rtdetr_r50vd_coco_o365"7 unmodified lines@spaces.GPU@torch.inference_mode()def run(image: PIL.Image.Image) -> tuple[PIL.Image.Image, list[dict]]:inputs = person_image_processor(images=image, return_tensors="pt").to(device)outputs = person_model(**inputs)results = person_image_processor.post_process_object_detection(64 unmodified linesreturn vertex_annotator.annotate(scene=annotated_frame, key_points=keypoints), human_readable_resultspaths = sorted(pathlib.Path("images").glob("*.jpg"))with gr.Blocks(css_paths="style.css") as demo:gr.Markdown(DESCRIPTION)with gr.Row():with gr.Column():input_image = gr.Image(label="Input Image", type="pil")run_button = gr.Button()with gr.Column():output_image = gr.Image(label="Output Image")output_json = gr.JSON(label="Output JSON")gr.Examples(examples=paths, inputs=input_image, outputs=[output_image, output_json], fn=run)run_button.click(fn=run,inputs=input_image,outputs=[output_image, output_json],)if __name__ == "__main__":6 unmodified lines789101112131415161718192021222324252627287 unmodified lines3637383940414264 unmodified lines1071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871886 unmodified lines"""import pathlibimport tempfileimport cv2import gradio as grimport numpy as npimport PIL.Imageimport spacesimport supervision as svimport torchimport tqdmfrom transformers import AutoProcessor, RTDetrForObjectDetection, VitPoseForPoseEstimationDESCRIPTION = "# ViTPose"MAX_NUM_FRAMES = 300device = torch.device("cuda" if torch.cuda.is_available() else "cpu")person_detector_name = "PekingU/rtdetr_r50vd_coco_o365"7 unmodified lines@spaces.GPU@torch.inference_mode()def process_image(image: PIL.Image.Image) -> tuple[PIL.Image.Image, list[dict]]:inputs = person_image_processor(images=image, return_tensors="pt").to(device)outputs = person_model(**inputs)results = person_image_processor.post_process_object_detection(64 unmodified linesreturn vertex_annotator.annotate(scene=annotated_frame, key_points=keypoints), human_readable_resultsdef process_video(video_path: str,progress: gr.Progress = gr.Progress(track_tqdm=True), # noqa: ARG001, B008) -> str:cap = cv2.VideoCapture(video_path)height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))fps = cap.get(cv2.CAP_PROP_FPS)num_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))fourcc = cv2.VideoWriter_fourcc(*"mp4v")with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as out_file:writer = cv2.VideoWriter(out_file.name, fourcc, fps, (width, height))for _ in tqdm.auto.tqdm(range(min(MAX_NUM_FRAMES, num_frames))):ok, frame = cap.read()if not ok:breakrgb_frame = frame[:, :, ::-1]annotated_frame, _ = process_image(PIL.Image.fromarray(rgb_frame))writer.write(np.asarray(annotated_frame)[:, :, ::-1])writer.release()cap.release()return out_file.nameprocess_video.zerogpu = True # type: ignorewith gr.Blocks(css_paths="style.css") as demo:gr.Markdown(DESCRIPTION)with gr.Tabs():with gr.Tab("Image"):with gr.Row():with gr.Column():input_image = gr.Image(label="Input Image", type="pil")run_button_image = gr.Button()with gr.Column():output_image = gr.Image(label="Output Image")output_json = gr.JSON(label="Output JSON")gr.Examples(examples=sorted(pathlib.Path("images").glob("*.jpg")),inputs=input_image,outputs=[output_image, output_json],fn=process_image,)run_button_image.click(fn=process_image,inputs=input_image,outputs=[output_image, output_json],)with gr.Tab("Video"):gr.Markdown(f"The input video will be truncated to {MAX_NUM_FRAMES} frames.")with gr.Row():with gr.Column():input_video = gr.Video(label="Input Video")run_button_video = gr.Button()with gr.Column():output_video = gr.Video(label="Output Video")gr.Examples(examples=sorted(pathlib.Path("videos").glob("*.mp4")),inputs=input_video,outputs=output_video,fn=process_video,cache_examples=False,)run_button_video.click(fn=process_video,inputs=input_video,outputs=output_video,)if __name__ == "__main__":
7 unmodified lines89101112137 unmodified lines"accelerate>=1.2.1","gradio>=5.11.0","hf-transfer>=0.1.9","setuptools>=75.8.0","spaces>=0.32.0","supervision>=0.25.1",7 unmodified lines8910111213147 unmodified lines"accelerate>=1.2.1","gradio>=5.11.0","hf-transfer>=0.1.9","opencv-python-headless>=4.10.0.84","setuptools>=75.8.0","spaces>=0.32.0","supervision>=0.25.1",
107 unmodified lines10810911011111211331 unmodified lines145146147148149150107 unmodified lines# gradio# matplotlib# opencv-python# pandas# scipy# supervision31 unmodified lines# via torchopencv-python==4.10.0.84# via supervisionorjson==3.10.14# via gradiopackaging==24.2107 unmodified lines10810911011111211311431 unmodified lines146147148149150151152153107 unmodified lines# gradio# matplotlib# opencv-python# opencv-python-headless# pandas# scipy# supervision31 unmodified lines# via torchopencv-python==4.10.0.84# via supervisionopencv-python-headless==4.10.0.84# via vitpose-transformers (pyproject.toml)orjson==3.10.14# via gradiopackaging==24.2
936 unmodified lines937938939940941942872 unmodified lines1815181618171818181918206 unmodified lines182718281829183018311832936 unmodified lines{ url = "https://files.pythonhosted.org/packages/ec/6c/fab8113424af5049f85717e8e527ca3773299a3c6b02506e66436e19874f/opencv_python-4.10.0.84-cp37-abi3-win_amd64.whl", hash = "sha256:32dbbd94c26f611dc5cc6979e6b7aa1f55a64d6b463cc1dcd3c95505a63e48fe", size = 38842521 },][[package]]name = "orjson"version = "3.10.14"872 unmodified lines{ name = "accelerate" },{ name = "gradio" },{ name = "hf-transfer" },{ name = "setuptools" },{ name = "spaces" },{ name = "supervision" },6 unmodified lines{ name = "accelerate", specifier = ">=1.2.1" },{ name = "gradio", specifier = ">=5.11.0" },{ name = "hf-transfer", specifier = ">=0.1.9" },{ name = "setuptools", specifier = ">=75.8.0" },{ name = "spaces", specifier = ">=0.32.0" },{ name = "supervision", specifier = ">=0.25.1" },936 unmodified lines937938939940941942943944945946947948949950951952953954955956957958959872 unmodified lines18321833183418351836183718386 unmodified lines1845184618471848184918501851936 unmodified lines{ url = "https://files.pythonhosted.org/packages/ec/6c/fab8113424af5049f85717e8e527ca3773299a3c6b02506e66436e19874f/opencv_python-4.10.0.84-cp37-abi3-win_amd64.whl", hash = "sha256:32dbbd94c26f611dc5cc6979e6b7aa1f55a64d6b463cc1dcd3c95505a63e48fe", size = 38842521 },][[package]]name = "opencv-python-headless"version = "4.10.0.84"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "numpy" },]sdist = { url = "https://files.pythonhosted.org/packages/2f/7e/d20f68a5f1487adf19d74378d349932a386b1ece3be9be9915e5986db468/opencv-python-headless-4.10.0.84.tar.gz", hash = "sha256:f2017c6101d7c2ef8d7bc3b414c37ff7f54d64413a1847d89970b6b7069b4e1a", size = 95117755 }wheels = [{ url = "https://files.pythonhosted.org/packages/1c/9b/583c8d9259f6fc19413f83fd18dd8e6cbc8eefb0b4dc6da52dd151fe3272/opencv_python_headless-4.10.0.84-cp37-abi3-macosx_11_0_arm64.whl", hash = "sha256:a4f4bcb07d8f8a7704d9c8564c224c8b064c63f430e95b61ac0bffaa374d330e", size = 54835657 },{ url = "https://files.pythonhosted.org/packages/c0/7b/b4c67f5dad7a9a61c47f7a39e4050e8a4628bd64b3c3daaeb755d759f928/opencv_python_headless-4.10.0.84-cp37-abi3-macosx_12_0_x86_64.whl", hash = "sha256:5ae454ebac0eb0a0b932e3406370aaf4212e6a3fdb5038cc86c7aea15a6851da", size = 56475470 },{ url = "https://files.pythonhosted.org/packages/91/61/f838ce2046f3ec3591ea59ea3549085e399525d3b4558c4ed60b55ed88c0/opencv_python_headless-4.10.0.84-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:46071015ff9ab40fccd8a163da0ee14ce9846349f06c6c8c0f2870856ffa45db", size = 29329705 },{ url = "https://files.pythonhosted.org/packages/d1/09/248f86a404567303cdf120e4a301f389b68e3b18e5c0cc428de327da609c/opencv_python_headless-4.10.0.84-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:377d08a7e48a1405b5e84afcbe4798464ce7ee17081c1c23619c8b398ff18295", size = 49858781 },{ url = "https://files.pythonhosted.org/packages/30/c0/66f88d58500e990a9a0a5c06f98862edf1d0a3a430781218a8c193948438/opencv_python_headless-4.10.0.84-cp37-abi3-win32.whl", hash = "sha256:9092404b65458ed87ce932f613ffbb1106ed2c843577501e5768912360fc50ec", size = 28675298 },{ url = "https://files.pythonhosted.org/packages/26/d0/22f68eb23eea053a31655960f133c0be9726c6a881547e6e9e7e2a946c4f/opencv_python_headless-4.10.0.84-cp37-abi3-win_amd64.whl", hash = "sha256:afcf28bd1209dd58810d33defb622b325d3cbe49dcd7a43a902982c33e5fad05", size = 38754031 },][[package]]name = "orjson"version = "3.10.14"872 unmodified lines{ name = "accelerate" },{ name = "gradio" },{ name = "hf-transfer" },{ name = "opencv-python-headless" },{ name = "setuptools" },{ name = "spaces" },{ name = "supervision" },6 unmodified lines{ name = "accelerate", specifier = ">=1.2.1" },{ name = "gradio", specifier = ">=5.11.0" },{ name = "hf-transfer", specifier = ">=0.1.9" },{ name = "opencv-python-headless", specifier = ">=4.10.0.84" },{ name = "setuptools", specifier = ">=75.8.0" },{ name = "spaces", specifier = ">=0.32.0" },{ name = "supervision", specifier = ">=0.25.1" },
123456These videos are from the following public domain:
- https://www.pexels.com/video/young-guy-doing-break-dance-on-the-street-5362370/- https://www.pexels.com/video/a-woman-dancing-at-home-6003986/- https://www.pexels.com/video/long-haired-man-dancing-in-a-library-6344381/- https://www.pexels.com/video/a-female-model-dancing-around-6815069/123version https://git-lfs.github.com/spec/v1oid sha256:747f9c2f9d19e4955603e1a13b69663187882d4c6a8fbcad18ddbd04ee792d4dsize 1972564123version https://git-lfs.github.com/spec/v1oid sha256:1044083afc06aa6f956838c7fcd582c9cfd59ea3a994adc8a0f5889ffca4d9c8size 2494082123version https://git-lfs.github.com/spec/v1oid sha256:7763476045f4683d53d751fb8befaf637c0101a0693e72f5b582e6aa5ac63cacsize 3967587123version https://git-lfs.github.com/spec/v1oid sha256:44045b239c0f523bfeedc5871019ae9f67525fcf65ba46d7ca4516994e6b2f57size 2617714.gitattributes+1
app.py+79-17
pyproject.toml+1
requirements.txt+3
uv.lock+19
videos/README.mdAdded+6
videos/pexels-allan-mas-5362370.mp4Added+3
videos/pexels-artem-podrez-6003986.mp4Added+3
videos/pexels-c-technical-6344381.mp4Added+3
videos/pexels-roman-odintsov-6815069.mp4Added+3