FridayCodehhr commited on
Commit
0f273d1
·
verified ·
1 Parent(s): a9d5e1b

Upload 10 files

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -21,14 +21,9 @@ async def analyze_endpoint(file: UploadFile = File(...)):
21
 
22
  # Save to a known fixed path for the viewing endpoint
23
  # Note: This is not thread-safe/multi-user safe, but sufficient for this local demo.
24
- fixed_path = "latest_upload.pdf"
25
- with open(fixed_path, "wb") as f:
26
- # seek back to start if we copied it (but we didn't read it yet)
27
- # Actually file is an UploadFile, we can just save it.
28
- # But we already copied to tmp. Let's just use the tmp copy logic but to fixed path.
29
- pass
30
 
31
- # Actually, let's just write directly to fixed_path!
32
  with open(fixed_path, "wb") as f:
33
  shutil.copyfileobj(file.file, f)
34
 
@@ -48,7 +43,7 @@ import fitz
48
 
49
  @app.get("/pdf/page/{page_num}")
50
  async def get_pdf_page(page_num: int):
51
- path = "latest_upload.pdf"
52
  if not os.path.exists(path):
53
  return Response(status_code=404)
54
 
 
21
 
22
  # Save to a known fixed path for the viewing endpoint
23
  # Note: This is not thread-safe/multi-user safe, but sufficient for this local demo.
24
+ # Using /tmp to avoid permission issues on read-only filesystems (Hugging Face Spaces)
25
+ fixed_path = "/tmp/latest_upload.pdf"
 
 
 
 
26
 
 
27
  with open(fixed_path, "wb") as f:
28
  shutil.copyfileobj(file.file, f)
29
 
 
43
 
44
  @app.get("/pdf/page/{page_num}")
45
  async def get_pdf_page(page_num: int):
46
+ path = "/tmp/latest_upload.pdf"
47
  if not os.path.exists(path):
48
  return Response(status_code=404)
49