Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,6 +69,28 @@ def safe_get(url: str, timeout: int = 15):
|
|
| 69 |
r.raise_for_status()
|
| 70 |
return r
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def fetch_bytes(src: str, stream_threshold: int = STREAM_THRESHOLD, timeout: int = 60, progress=None) -> bytes:
|
| 73 |
if progress is not None:
|
| 74 |
progress(0.05, desc="Checking remote/local source...")
|
|
|
|
| 69 |
r.raise_for_status()
|
| 70 |
return r
|
| 71 |
|
| 72 |
+
def _temp_file(data: bytes, suffix: str) -> str:
|
| 73 |
+
"""
|
| 74 |
+
Write *data* to a temporary file and return its absolute path.
|
| 75 |
+
|
| 76 |
+
Parameters
|
| 77 |
+
----------
|
| 78 |
+
data: bytes
|
| 79 |
+
The binary content to store.
|
| 80 |
+
suffix: str
|
| 81 |
+
File extension **including** the leading dot (".jpg", ".mp4", …).
|
| 82 |
+
|
| 83 |
+
Returns
|
| 84 |
+
-------
|
| 85 |
+
str
|
| 86 |
+
Path to the created temporary file.
|
| 87 |
+
"""
|
| 88 |
+
fd, path = tempfile.mkstemp(suffix=suffix)
|
| 89 |
+
os.close(fd) # close low‑level descriptor
|
| 90 |
+
with open(path, "wb") as f:
|
| 91 |
+
f.write(data)
|
| 92 |
+
return path
|
| 93 |
+
|
| 94 |
def fetch_bytes(src: str, stream_threshold: int = STREAM_THRESHOLD, timeout: int = 60, progress=None) -> bytes:
|
| 95 |
if progress is not None:
|
| 96 |
progress(0.05, desc="Checking remote/local source...")
|