Gradio使用记录

启动 Gradio 时自动打开本地浏览器网页

1
2
3
# 启动 Gradio 接口
iface.launch(inbrowser=True) # inbrowser=True 则会自动打开本地浏览器网页
# iface.launch(inbrowser=True, share=True) # share=True 则会分享网页链接

Gradio 默认上传文件的文件夹

  • Gradio 默认上传文件的文件夹 C:\Users\lovo\AppData\Local\Temp\gradio
  • PyInstaller 打包后exe程序文件临时释放的文件夹(需要ctrl+c结束程序才能自动删除文件夹, 直接关闭cmd窗口的话文件夹可能不会自动删除) C:\Users\lovo\AppData\Local\Temp\_MEIxxxxxx

Gradio打包

使用PyInstaller

新建纯净的打包环境( pyinstaller 默认打包环境内的所有包)

1
2
3
conda create -n temp
activate temp
pip install -r requirements.txt

修改spec文件

  • Gradio打包需添加
1
2
3
4
datas = []
datas += collect_data_files('gradio_client')
datas += collect_data_files('gradio')
datas += collect_data_files('safehttpx')
1
module_collection_mode={ 'gradio': 'py',},
  • 修改spec文件
1
['gui.py'], # 需要打包的文件名
1
icon=['camera.ico'], # 图标名称
  • spec文件总览
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files

datas = []
datas += collect_data_files('gradio_client')
datas += collect_data_files('gradio')
datas += collect_data_files('safehttpx')


a = Analysis(
['gui.py'],
pathex=[],
binaries=[],
datas=datas,
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
module_collection_mode={ 'gradio': 'py',},
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='gui',
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=['camera.ico'],
)