AvaLovelace commited on
Commit
1bb48b0
·
1 Parent(s): ea83f5f

Download LDraw library instead of keeping it in the repo

Browse files
Files changed (3) hide show
  1. .gitignore +9 -1
  2. app.py +17 -9
  3. ldraw.zip +0 -3
.gitignore CHANGED
@@ -9,5 +9,13 @@ wheels/
9
  # Virtual environments
10
  .venv
11
 
 
 
 
 
 
 
 
12
  .idea
13
- .gradio
 
 
9
  # Virtual environments
10
  .venv
11
 
12
+ # Gurobi files
13
+ gurobi.lic
14
+
15
+ # LDraw files
16
+ ldraw
17
+ complete.zip
18
+
19
  .idea
20
+ .gradio
21
+ out
app.py CHANGED
@@ -1,29 +1,34 @@
1
  import os
2
  import subprocess
 
3
  from dataclasses import fields
 
4
 
5
  import gradio as gr
6
  import transformers
7
  from legogpt.models import LegoGPT, LegoGPTConfig
8
- import zipfile
9
 
10
 
11
  def setup():
12
  # Set up Gurobi licence
 
13
  licence_lines = []
14
  for secret_name in ['WLSACCESSID', 'WLSSECRET', 'LICENSEID']:
15
  secret = os.environ.get(secret_name)
16
  if not secret:
17
  raise ValueError(f'Env variable {secret_name} not found. Please set it in the Hugging Face Space settings.')
18
  licence_lines.append(f'{secret_name}={secret}\n')
19
- with open('gurobi.lic', 'w') as f:
20
  f.writelines(licence_lines)
21
- os.environ['GRB_LICENSE_FILE'] = os.path.abspath('gurobi.lic')
22
 
23
- # Set LDraw library path
24
- with zipfile.ZipFile('ldraw.zip') as zip_ref:
25
- zip_ref.extractall('ImportLDraw')
26
- os.environ['LDRAW_LIBRARY_PATH'] = os.path.abspath('ImportLDraw/ldraw')
 
 
 
27
 
28
 
29
  def main():
@@ -57,8 +62,11 @@ def main():
57
 
58
  # Render results and write to files
59
  render_lego_filename = 'render_lego.py'
60
- ldr_filename = os.path.abspath('output.ldr')
61
- img_filename = os.path.abspath('output.png')
 
 
 
62
  with open(ldr_filename, 'w') as f:
63
  f.write(output['lego'].to_ldr())
64
 
 
1
  import os
2
  import subprocess
3
+ import zipfile
4
  from dataclasses import fields
5
+ from urllib.request import urlretrieve
6
 
7
  import gradio as gr
8
  import transformers
9
  from legogpt.models import LegoGPT, LegoGPTConfig
 
10
 
11
 
12
  def setup():
13
  # Set up Gurobi licence
14
+ licence_filename = 'gurobi.lic'
15
  licence_lines = []
16
  for secret_name in ['WLSACCESSID', 'WLSSECRET', 'LICENSEID']:
17
  secret = os.environ.get(secret_name)
18
  if not secret:
19
  raise ValueError(f'Env variable {secret_name} not found. Please set it in the Hugging Face Space settings.')
20
  licence_lines.append(f'{secret_name}={secret}\n')
21
+ with open(licence_filename, 'w') as f:
22
  f.writelines(licence_lines)
23
+ os.environ['GRB_LICENSE_FILE'] = os.path.abspath(licence_filename)
24
 
25
+ # Download LDraw part library and set LDraw library path
26
+ ldraw_zip_url = 'https://library.ldraw.org/library/updates/complete.zip'
27
+ ldraw_zip_filename = 'complete.zip'
28
+ urlretrieve(ldraw_zip_url, ldraw_zip_filename)
29
+ with zipfile.ZipFile(ldraw_zip_filename) as zip_ref:
30
+ zip_ref.extractall()
31
+ os.environ['LDRAW_LIBRARY_PATH'] = os.path.abspath('ldraw')
32
 
33
 
34
  def main():
 
62
 
63
  # Render results and write to files
64
  render_lego_filename = 'render_lego.py'
65
+
66
+ output_dir = os.path.abspath('out')
67
+ os.makedirs(output_dir, exist_ok=True)
68
+ ldr_filename = os.path.join(output_dir, 'output.ldr')
69
+ img_filename = os.path.join(output_dir, 'output.png')
70
  with open(ldr_filename, 'w') as f:
71
  f.write(output['lego'].to_ldr())
72
 
ldraw.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:3115747ca75879100a799ebabd9bf25302b170828bda39ab3dd9379a26ae3d07
3
- size 99633074