Spaces:
Running
Running
File size: 1,261 Bytes
0e38162 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import requests, os, time
backend = "http://localhost:8000"
uploads = os.path.join(os.path.dirname(__file__), "..", "uploads")
reports = os.path.join(os.path.dirname(__file__), "..", "reports")
os.makedirs(reports, exist_ok=True)
for i in range(14, 21):
paper = f"paper_{i:02d}.pdf"
path = os.path.join(uploads, paper)
report = os.path.join(reports, f"{paper[:-4]}_report.pdf")
print(f"{paper}: uploading...")
with open(path, "rb") as f:
r = requests.post(
f"{backend}/analyze", files={"file": (paper, f, "application/pdf")}
)
if r.ok:
job_id = r.json()["job_id"]
print(f" job: {job_id}")
for _ in range(90):
time.sleep(5)
j = requests.get(f"{backend}/jobs/{job_id}").json()
status = j.get("status", "")
print(f" status: {status}")
if status == "completed":
r2 = requests.get(f"{backend}/reports/{job_id}/pdf", stream=True)
with open(report, "wb") as out:
for chunk in r2.iter_content():
out.write(chunk)
print(f" saved: {report}")
break
elif status in ["failed"]:
break
print()
|