Skip to content

Commit 8c158f2

Browse files
committed
Fix onedir pyinstall
Use relative paths for install pyinstaller web/shark_sd.spec creates an exe
1 parent 8c3eabd commit 8c158f2

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

web/index.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77
from PIL import Image
88
import json
99
import os
10+
import sys
1011
from random import randint
1112
from numpy import iinfo
1213
import numpy as np
1314

15+
def resource_path(relative_path):
16+
""" Get absolute path to resource, works for dev and for PyInstaller """
17+
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
18+
return os.path.join(base_path, relative_path)
1419

1520
prompt_examples = []
16-
prompt_loc = "./prompts.json"
21+
prompt_loc = resource_path("prompts.json")
1722
if os.path.exists(prompt_loc):
18-
with open("./prompts.json", encoding="utf-8") as fopen:
23+
with open(prompt_loc, encoding="utf-8") as fopen:
1924
prompt_examples = json.load(fopen)
2025

26+
nodlogo_loc = resource_path("logos/nod-logo.png")
27+
sdlogo_loc = resource_path("logos/sd-demo-logo.png")
2128

2229
demo_css = """
2330
.gradio-container {background-color: black}
@@ -43,8 +50,8 @@
4350
with gr.Blocks(css=demo_css) as shark_web:
4451

4552
with gr.Row(elem_id="ui_title"):
46-
nod_logo = Image.open("./logos/nod-logo.png")
47-
logo2 = Image.open("./logos/sd-demo-logo.png")
53+
nod_logo = Image.open(nodlogo_loc)
54+
logo2 = Image.open(sdlogo_loc)
4855
with gr.Row():
4956
with gr.Column(scale=1, elem_id="demo_title_outer"):
5057
gr.Image(

web/index.spec

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ datas += copy_metadata('torchvision')
1919
datas += copy_metadata('torch-mlir')
2020
datas += copy_metadata('diffusers')
2121
datas += copy_metadata('transformers')
22-
datas += copy_metadata('gradio')
22+
datas += collect_data_files('gradio')
2323
datas += collect_data_files('iree')
2424
#datas += copy_metadata('iree')
2525
datas += collect_data_files('shark')
26+
datas += [
27+
( 'prompts.json', '.' ),
28+
( 'logos/*', 'logos' )
29+
]
2630

2731
block_cipher = None
2832

@@ -32,7 +36,7 @@ a = Analysis(
3236
pathex=['.'],
3337
binaries=[],
3438
datas=datas,
35-
hiddenimports=['shark', 'shark.*', 'shark.shark_inference', 'shark_inference', 'iree.tools.core'],
39+
hiddenimports=['shark', 'shark.*', 'shark.shark_inference', 'shark_inference', 'iree.tools.core', 'gradio'],
3640
hookspath=[],
3741
hooksconfig={},
3842
runtime_hooks=[],
@@ -49,7 +53,7 @@ exe = EXE(
4953
a.scripts,
5054
[],
5155
exclude_binaries=True,
52-
name='index',
56+
name='shark_sd',
5357
debug=False,
5458
bootloader_ignore_signals=False,
5559
strip=False,
@@ -69,5 +73,5 @@ coll = COLLECT(
6973
strip=False,
7074
upx=True,
7175
upx_exclude=[],
72-
name='index',
76+
name='shark_sd',
7377
)

0 commit comments

Comments
 (0)