Theflame47 commited on
Commit
59fd8df
·
verified ·
1 Parent(s): e159005

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -126,13 +126,12 @@ def _build_product(blob: Dict[str, Any], currency: str, logs: List[str]) -> Dict
126
  }
127
 
128
 
129
- def run(currency: str) -> Generator[Tuple[str, str, str], None, None]:
130
  logs: List[str] = []
131
  result: Dict[str, Any] = {}
132
- dl_path = ""
133
 
134
  def flush():
135
- return "\n".join(logs), json.dumps(result, indent=2), dl_path
136
 
137
  try:
138
  _log(logs, "START")
@@ -142,18 +141,17 @@ def run(currency: str) -> Generator[Tuple[str, str, str], None, None]:
142
  _log(logs, f"SHOP_LIST {json.dumps(shops)}")
143
  yield flush()
144
 
145
- blob = _find_first_valid_pair(logs)
146
- yield flush()
147
-
148
- result = _build_product(blob, currency or "USD", logs)
149
- yield flush()
150
-
151
  fd, path = tempfile.mkstemp(prefix="shops_", suffix=".json")
152
  os.close(fd)
153
  with open(path, "w", encoding="utf-8") as f:
154
  json.dump(shops, f, indent=2)
155
- dl_path = path
 
156
 
 
 
 
 
157
  _log(logs, "DONE")
158
  yield flush()
159
 
@@ -170,8 +168,7 @@ with gr.Blocks(title="Printify Catalog Probe") as demo:
170
  btn = gr.Button("Run")
171
  logs = gr.Textbox(label="Logs", lines=18)
172
  out = gr.Textbox(label="Output JSON", lines=18)
173
- dl = gr.File(label="Download Shops JSON")
174
 
175
- btn.click(run, inputs=[currency], outputs=[logs, out, dl])
176
 
177
  demo.queue().launch()
 
126
  }
127
 
128
 
129
+ def run(currency: str) -> Generator[Tuple[str, str], None, None]:
130
  logs: List[str] = []
131
  result: Dict[str, Any] = {}
 
132
 
133
  def flush():
134
+ return "\n".join(logs), json.dumps(result, indent=2)
135
 
136
  try:
137
  _log(logs, "START")
 
141
  _log(logs, f"SHOP_LIST {json.dumps(shops)}")
142
  yield flush()
143
 
 
 
 
 
 
 
144
  fd, path = tempfile.mkstemp(prefix="shops_", suffix=".json")
145
  os.close(fd)
146
  with open(path, "w", encoding="utf-8") as f:
147
  json.dump(shops, f, indent=2)
148
+ _log(logs, f"SHOPS_JSON_WRITTEN {path}")
149
+ yield flush()
150
 
151
+ blob = _find_first_valid_pair(logs)
152
+ yield flush()
153
+
154
+ result = _build_product(blob, currency or "USD", logs)
155
  _log(logs, "DONE")
156
  yield flush()
157
 
 
168
  btn = gr.Button("Run")
169
  logs = gr.Textbox(label="Logs", lines=18)
170
  out = gr.Textbox(label="Output JSON", lines=18)
 
171
 
172
+ btn.click(run, inputs=[currency], outputs=[logs, out])
173
 
174
  demo.queue().launch()