From 1f443b234410fdf1fe930bc4eaa7b8dc668b0cee Mon Sep 17 00:00:00 2001 From: Jianzhu Guo Date: Thu, 25 Jul 2024 18:50:54 +0800 Subject: [PATCH] feat: add scripts for one click windows (#219) * feat: windows one-click installation * chore: format --------- Co-authored-by: zzzweakman <1819489045@qq.com> --- .gitignore | 4 ++++ app.py | 5 ++++- inference.py | 5 +++++ src/utils/check_windows_port.py | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/utils/check_windows_port.py diff --git a/.gitignore b/.gitignore index a6a28fc..ad97cdf 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ tmp/* .vscode/launch.json **/*.DS_Store gradio_temp/** + +# Windows dependencies +ffmpeg/ +LivePortrait_env/ diff --git a/app.py b/app.py index ad2b4f8..4faa827 100644 --- a/app.py +++ b/app.py @@ -32,11 +32,14 @@ def fast_check_ffmpeg(): tyro.extras.set_accent_color("bright_cyan") args = tyro.cli(ArgumentConfig) +ffmpeg_dir = os.path.join(os.getcwd(), "ffmpeg") +if osp.exists(ffmpeg_dir): + os.environ["PATH"] += (os.pathsep + ffmpeg_dir) + if not fast_check_ffmpeg(): raise ImportError( "FFmpeg is not installed. Please install FFmpeg (including ffmpeg and ffprobe) before running this script. https://ffmpeg.org/download.html" ) - # specify configs for inference inference_cfg = partial_fields(InferenceConfig, args.__dict__) # use attribute of args to initial InferenceConfig crop_cfg = partial_fields(CropConfig, args.__dict__) # use attribute of args to initial CropConfig diff --git a/inference.py b/inference.py index 9480523..686dd81 100644 --- a/inference.py +++ b/inference.py @@ -1,5 +1,6 @@ # coding: utf-8 +import os import os.path as osp import tyro import subprocess @@ -33,6 +34,10 @@ def main(): tyro.extras.set_accent_color("bright_cyan") args = tyro.cli(ArgumentConfig) + ffmpeg_dir = os.path.join(os.getcwd(), "ffmpeg") + if osp.exists(ffmpeg_dir): + os.environ["PATH"] += (os.pathsep + ffmpeg_dir) + if not fast_check_ffmpeg(): raise ImportError( "FFmpeg is not installed. Please install FFmpeg (including ffmpeg and ffprobe) before running this script. https://ffmpeg.org/download.html" diff --git a/src/utils/check_windows_port.py b/src/utils/check_windows_port.py new file mode 100644 index 0000000..c2f9728 --- /dev/null +++ b/src/utils/check_windows_port.py @@ -0,0 +1,18 @@ +import socket +import sys + +if len(sys.argv) != 2: + print("Usage: python check_port.py ") + sys.exit(1) + +port = int(sys.argv[1]) + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.settimeout(1) +result = sock.connect_ex(('127.0.0.1', port)) + +if result == 0: + print("LISTENING") +else: + print("NOT LISTENING") +sock.close