Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import time
|
| 3 |
import json
|
| 4 |
import tempfile
|
| 5 |
-
from typing import Dict, Any, List, Generator, Tuple
|
| 6 |
|
| 7 |
import requests
|
| 8 |
import gradio as gr
|
|
@@ -62,7 +62,6 @@ def _find_first_valid_pair(logs: List[str]) -> Dict[str, Any]:
|
|
| 62 |
variants = vr.get("variants")
|
| 63 |
if isinstance(variants, list) and variants:
|
| 64 |
_log(logs, f"FOUND {len(variants)} variants")
|
| 65 |
-
_log(logs, f"Blueprint {bp_id} / Provider {p_id}: fetching print areas")
|
| 66 |
|
| 67 |
return {
|
| 68 |
"blueprint": bp,
|
|
@@ -74,10 +73,6 @@ def _find_first_valid_pair(logs: List[str]) -> Dict[str, Any]:
|
|
| 74 |
"GET",
|
| 75 |
f"/v1/catalog/blueprints/{bp_id}/print_providers/{p_id}/shipping.json",
|
| 76 |
),
|
| 77 |
-
"printAreas": _req(
|
| 78 |
-
"GET",
|
| 79 |
-
f"/v1/catalog/blueprints/{bp_id}/print_providers/{p_id}/print_areas.json",
|
| 80 |
-
),
|
| 81 |
}
|
| 82 |
|
| 83 |
raise RuntimeError("No blueprint/provider pair with variants found.")
|
|
@@ -127,18 +122,16 @@ def _build_product(blob: Dict[str, Any], currency: str, logs: List[str]) -> Dict
|
|
| 127 |
},
|
| 128 |
"description": description,
|
| 129 |
"variants": snapshot,
|
| 130 |
-
"printAreas": blob.get("printAreas"),
|
| 131 |
"raw": blob,
|
| 132 |
}
|
| 133 |
|
| 134 |
|
| 135 |
-
def run(currency: str) -> Generator[Tuple[str, str
|
| 136 |
logs: List[str] = []
|
| 137 |
result: Dict[str, Any] = {}
|
| 138 |
-
dl_path: Optional[str] = None
|
| 139 |
|
| 140 |
def flush():
|
| 141 |
-
return "\n".join(logs), json.dumps(result, indent=2)
|
| 142 |
|
| 143 |
try:
|
| 144 |
_log(logs, "START")
|
|
@@ -160,13 +153,11 @@ def run(currency: str) -> Generator[Tuple[str, str, Optional[str]], None, None]:
|
|
| 160 |
|
| 161 |
result = _build_product(blob, currency or "USD", logs)
|
| 162 |
_log(logs, "DONE")
|
| 163 |
-
dl_path = path
|
| 164 |
yield flush()
|
| 165 |
|
| 166 |
except Exception as e:
|
| 167 |
_log(logs, f"ERROR: {e}")
|
| 168 |
result = {"error": str(e)}
|
| 169 |
-
dl_path = None
|
| 170 |
yield flush()
|
| 171 |
|
| 172 |
|
|
@@ -177,8 +168,7 @@ with gr.Blocks(title="Printify Catalog Probe") as demo:
|
|
| 177 |
btn = gr.Button("Run")
|
| 178 |
logs = gr.Textbox(label="Logs", lines=18)
|
| 179 |
out = gr.Textbox(label="Output JSON", lines=18)
|
| 180 |
-
dl = gr.File(label="Download Shops JSON")
|
| 181 |
|
| 182 |
-
btn.click(run, inputs=[currency], outputs=[logs, out
|
| 183 |
|
| 184 |
-
demo.queue().launch(
|
|
|
|
| 2 |
import time
|
| 3 |
import json
|
| 4 |
import tempfile
|
| 5 |
+
from typing import Dict, Any, List, Generator, Tuple
|
| 6 |
|
| 7 |
import requests
|
| 8 |
import gradio as gr
|
|
|
|
| 62 |
variants = vr.get("variants")
|
| 63 |
if isinstance(variants, list) and variants:
|
| 64 |
_log(logs, f"FOUND {len(variants)} variants")
|
|
|
|
| 65 |
|
| 66 |
return {
|
| 67 |
"blueprint": bp,
|
|
|
|
| 73 |
"GET",
|
| 74 |
f"/v1/catalog/blueprints/{bp_id}/print_providers/{p_id}/shipping.json",
|
| 75 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
|
| 78 |
raise RuntimeError("No blueprint/provider pair with variants found.")
|
|
|
|
| 122 |
},
|
| 123 |
"description": description,
|
| 124 |
"variants": snapshot,
|
|
|
|
| 125 |
"raw": blob,
|
| 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")
|
|
|
|
| 153 |
|
| 154 |
result = _build_product(blob, currency or "USD", logs)
|
| 155 |
_log(logs, "DONE")
|
|
|
|
| 156 |
yield flush()
|
| 157 |
|
| 158 |
except Exception as e:
|
| 159 |
_log(logs, f"ERROR: {e}")
|
| 160 |
result = {"error": str(e)}
|
|
|
|
| 161 |
yield flush()
|
| 162 |
|
| 163 |
|
|
|
|
| 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()
|