Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from typing import Dict, Any, List, Generator, Tuple, Optional
|
|
| 6 |
|
| 7 |
import requests
|
| 8 |
import gradio as gr
|
|
|
|
| 9 |
|
| 10 |
PRINTIFY_BASE = "https://api.printify.com"
|
| 11 |
DEFAULT_BASE_PRICE = 24.99
|
|
@@ -202,7 +203,26 @@ def _upload_grid_from_file(logs: List[str]) -> Dict[str, Any]:
|
|
| 202 |
if not os.path.exists(path):
|
| 203 |
raise RuntimeError(f"Grid image not found at {path}")
|
| 204 |
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
with open(path, "rb") as f:
|
| 208 |
r = requests.post(
|
|
|
|
| 6 |
|
| 7 |
import requests
|
| 8 |
import gradio as gr
|
| 9 |
+
import base64
|
| 10 |
|
| 11 |
PRINTIFY_BASE = "https://api.printify.com"
|
| 12 |
DEFAULT_BASE_PRICE = 24.99
|
|
|
|
| 203 |
if not os.path.exists(path):
|
| 204 |
raise RuntimeError(f"Grid image not found at {path}")
|
| 205 |
|
| 206 |
+
with open(path, "rb") as f:
|
| 207 |
+
b64 = base64.b64encode(f.read()).decode("ascii")
|
| 208 |
+
|
| 209 |
+
payload = {
|
| 210 |
+
"file_name": GRID_FILENAME,
|
| 211 |
+
"contents": b64,
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
_log(logs, f"UPLOADING_GRID path={path} bytes={len(b64)}")
|
| 215 |
+
resp = _req("POST", "/v1/uploads/images.json", json_body=payload)
|
| 216 |
+
|
| 217 |
+
if not isinstance(resp, dict) or not resp.get("id"):
|
| 218 |
+
raise RuntimeError(f"Unexpected upload response: {str(resp)[:500]}")
|
| 219 |
+
|
| 220 |
+
_log(
|
| 221 |
+
logs,
|
| 222 |
+
f"GRID_UPLOAD id={resp.get('id')} file={resp.get('file_name')} "
|
| 223 |
+
f"w={resp.get('width')} h={resp.get('height')}",
|
| 224 |
+
)
|
| 225 |
+
return resp
|
| 226 |
|
| 227 |
with open(path, "rb") as f:
|
| 228 |
r = requests.post(
|