feat: convert gradio app into .exe executable file

This commit is contained in:
Ink 2024-09-02 19:12:56 +08:00
parent ddc8c21f24
commit 961bf2e35f
4 changed files with 52 additions and 3 deletions

5
.gitignore vendored
View File

@ -3,4 +3,7 @@
.idea
.DS_Store
hivision_modnet.onnx
output/*.jpg
output/*.jpg
# build outputs
dist
build

6
app.py
View File

@ -1,3 +1,4 @@
import os
import gradio as gr
import onnxruntime
from src.face_judgement_align import IDphotos_create
@ -226,7 +227,8 @@ def idphoto_inference(
if __name__ == "__main__":
# 预加载 ONNX 模型
HY_HUMAN_MATTING_WEIGHTS_PATH = "./hivision_modnet.onnx"
root_dir = os.path.dirname(os.path.abspath(__file__))
HY_HUMAN_MATTING_WEIGHTS_PATH = os.path.join(root_dir, "hivision_modnet.onnx")
sess = onnxruntime.InferenceSession(HY_HUMAN_MATTING_WEIGHTS_PATH)
size_mode = ["尺寸列表", "只换底", "自定义尺寸"]
@ -319,7 +321,7 @@ if __name__ == "__main__":
components=[img_input],
samples=[
[path.as_posix()]
for path in sorted(pathlib.Path("images").rglob("*.jpg"))
for path in sorted(pathlib.Path(os.path.join(root_dir, "images")).rglob("*.jpg"))
],
)

44
app.spec Normal file
View File

@ -0,0 +1,44 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files
datas = [('hivisionai', 'hivisionai'), ('hivision_modnet.onnx', '.')]
datas += collect_data_files('gradio_client')
datas += collect_data_files('gradio')
a = Analysis(
['app.py'],
pathex=[],
binaries=[],
datas=datas,
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='HivisionIDPhotos',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['assets\hivisionai.ico'],
)

BIN
assets/hivisionai.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB