Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -525,27 +525,33 @@ def _mf_resolve_file(quickkey, filename):
|
|
| 525 |
return None
|
| 526 |
|
| 527 |
def _mf_dl_and_upload(job_id, dl_url, fname, base_status):
|
|
|
|
| 528 |
tmp_base=f"/tmp/mf_{job_id}"
|
| 529 |
os.makedirs(tmp_base, exist_ok=True)
|
| 530 |
tmp_path=os.path.join(tmp_base, fname)
|
| 531 |
try:
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
try: shutil.rmtree(tmp_base)
|
| 550 |
except: pass
|
| 551 |
return False
|
|
|
|
| 525 |
return None
|
| 526 |
|
| 527 |
def _mf_dl_and_upload(job_id, dl_url, fname, base_status):
|
| 528 |
+
import requests
|
| 529 |
tmp_base=f"/tmp/mf_{job_id}"
|
| 530 |
os.makedirs(tmp_base, exist_ok=True)
|
| 531 |
tmp_path=os.path.join(tmp_base, fname)
|
| 532 |
try:
|
| 533 |
+
r=requests.get(dl_url, headers={"User-Agent":MF_UA}, stream=True, timeout=60, allow_redirects=True)
|
| 534 |
+
if r.status_code!=200:
|
| 535 |
+
jobs[job_id]["status"]=f"{base_status} → HTTP {r.status_code} {r.headers.get('content-type','')[:40]} len={r.headers.get('content-length','?')}"
|
| 536 |
+
try: r.close()
|
| 537 |
+
except: pass
|
| 538 |
+
return False
|
| 539 |
+
clen=int(r.headers.get("content-length",0) or 0)
|
| 540 |
+
written=0
|
| 541 |
+
with open(tmp_path,"wb") as out:
|
| 542 |
+
for chunk in r.iter_content(chunk_size=8*1024*1024):
|
| 543 |
+
if not chunk: continue
|
| 544 |
+
out.write(chunk); written+=len(chunk)
|
| 545 |
+
if written%(64*1024*1024)==0:
|
| 546 |
+
jobs[job_id]=dict(jobs.get(job_id,{}))
|
| 547 |
+
jobs[job_id]["status"]=f"{base_status} {written//1024//1024}MB"+(f"/{clen//1024//1024}MB" if clen else "")
|
| 548 |
+
try: r.close()
|
| 549 |
+
except: pass
|
| 550 |
+
if written==0:
|
| 551 |
+
jobs[job_id]["status"]=f"{base_status} → empty body (0 bytes)"
|
| 552 |
+
return False
|
| 553 |
+
except Exception as e:
|
| 554 |
+
jobs[job_id]["status"]=f"{base_status} → requests err: {str(e)[:160]}"
|
| 555 |
try: shutil.rmtree(tmp_base)
|
| 556 |
except: pass
|
| 557 |
return False
|