3rdaiOhpinFully commited on
Commit
7d73b4b
·
verified ·
1 Parent(s): 192e656

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -1,5 +1,12 @@
1
  import gradio as gr
2
- import os, json, zipfile, shutil
 
 
 
 
 
 
 
3
  from engine.mapper import map_all
4
 
5
  TEMPLATES = {
@@ -72,26 +79,32 @@ def clean_output():
72
  os.makedirs("output/proofs", exist_ok=True)
73
 
74
  def generate(image_path, template_name, prompt, use_optional_ai):
 
 
 
75
  clean_output()
76
 
77
  outputs, report = map_all(
78
  image_path=image_path,
79
  pieces=TEMPLATES[template_name],
80
- prompt=prompt,
81
  use_optional_ai=use_optional_ai,
82
  )
83
 
84
  files = []
 
85
  for piece_name, img in outputs.items():
86
  path = f"output/production_pngs/{piece_name}.png"
87
  img.save(path)
88
  files.append(path)
89
 
90
  report_path = "output/warnings.json"
 
91
  with open(report_path, "w") as f:
92
  json.dump(report, f, indent=2)
93
 
94
  zip_path = "output/soul_threading_output.zip"
 
95
  with zipfile.ZipFile(zip_path, "w") as z:
96
  for f in files:
97
  z.write(f, arcname=f"production_pngs/{os.path.basename(f)}")
@@ -99,7 +112,7 @@ def generate(image_path, template_name, prompt, use_optional_ai):
99
 
100
  return zip_path, json.dumps(report, indent=2)
101
 
102
- with gr.Blocks(css=CSS, title="Soul Threading") as demo:
103
  gr.Markdown(
104
  """
105
  # Soul Threading
@@ -110,16 +123,19 @@ Upload artwork, enter a design guidance prompt, select a garment, and export pro
110
  )
111
 
112
  image = gr.Image(type="filepath", label="Upload Artwork")
 
113
  template = gr.Dropdown(
114
  choices=list(TEMPLATES.keys()),
115
  value="mens_tshirt",
116
  label="Garment Template",
117
  )
 
118
  prompt = gr.Textbox(
119
  label="Textual Design Guidance Prompt",
120
  placeholder="Keep the main face centered. Use smoke/flames on sleeves. Protect text from seams. Use lower smoke for pocket.",
121
  lines=4,
122
  )
 
123
  use_ai = gr.Checkbox(
124
  label="Use optional Hugging Face AI processors if configured",
125
  value=False,
@@ -135,4 +151,4 @@ Upload artwork, enter a design guidance prompt, select a garment, and export pro
135
  outputs=[zip_out, report],
136
  )
137
 
138
- demo.launch()
 
1
  import gradio as gr
2
+ import os
3
+ import json
4
+ import zipfile
5
+ import shutil
6
+ from PIL import Image
7
+
8
+ Image.MAX_IMAGE_PIXELS = 200_000_000
9
+
10
  from engine.mapper import map_all
11
 
12
  TEMPLATES = {
 
79
  os.makedirs("output/proofs", exist_ok=True)
80
 
81
  def generate(image_path, template_name, prompt, use_optional_ai):
82
+ if not image_path:
83
+ return None, "Please upload artwork first."
84
+
85
  clean_output()
86
 
87
  outputs, report = map_all(
88
  image_path=image_path,
89
  pieces=TEMPLATES[template_name],
90
+ prompt=prompt or "",
91
  use_optional_ai=use_optional_ai,
92
  )
93
 
94
  files = []
95
+
96
  for piece_name, img in outputs.items():
97
  path = f"output/production_pngs/{piece_name}.png"
98
  img.save(path)
99
  files.append(path)
100
 
101
  report_path = "output/warnings.json"
102
+
103
  with open(report_path, "w") as f:
104
  json.dump(report, f, indent=2)
105
 
106
  zip_path = "output/soul_threading_output.zip"
107
+
108
  with zipfile.ZipFile(zip_path, "w") as z:
109
  for f in files:
110
  z.write(f, arcname=f"production_pngs/{os.path.basename(f)}")
 
112
 
113
  return zip_path, json.dumps(report, indent=2)
114
 
115
+ with gr.Blocks(title="Soul Threading") as demo:
116
  gr.Markdown(
117
  """
118
  # Soul Threading
 
123
  )
124
 
125
  image = gr.Image(type="filepath", label="Upload Artwork")
126
+
127
  template = gr.Dropdown(
128
  choices=list(TEMPLATES.keys()),
129
  value="mens_tshirt",
130
  label="Garment Template",
131
  )
132
+
133
  prompt = gr.Textbox(
134
  label="Textual Design Guidance Prompt",
135
  placeholder="Keep the main face centered. Use smoke/flames on sleeves. Protect text from seams. Use lower smoke for pocket.",
136
  lines=4,
137
  )
138
+
139
  use_ai = gr.Checkbox(
140
  label="Use optional Hugging Face AI processors if configured",
141
  value=False,
 
151
  outputs=[zip_out, report],
152
  )
153
 
154
+ demo.launch(css=CSS)