pvanand commited on
Commit
f07d3b7
·
verified ·
1 Parent(s): 31f86bc

Update doc_maker.py

Browse files
Files changed (1) hide show
  1. doc_maker.py +10 -3
doc_maker.py CHANGED
@@ -6,11 +6,15 @@ import json
6
  import os
7
  from datetime import datetime
8
  import uuid
 
9
 
10
  router = APIRouter()
11
 
12
  BASE_URL = "https://pvanand-doc-maker.hf.space/api/v1/"
13
 
 
 
 
14
  class DocumentPart(BaseModel):
15
  pageNo: int
16
  content: str
@@ -27,8 +31,8 @@ def get_download_url(file_id: str) -> str:
27
 
28
  def get_document_path(doc_id: str) -> str:
29
  """Get the full path for a document file"""
30
- os.makedirs("documents", exist_ok=True)
31
- return f"documents/{doc_id}.json"
32
 
33
  def update_document(doc_id: str, page_no: int, content: str) -> Dict:
34
  """Update or create document with new page content"""
@@ -66,7 +70,10 @@ async def add_document_part(part: DocumentPart):
66
  download_url=get_download_url(doc_id)
67
  )
68
  except Exception as e:
69
- raise HTTPException(status_code=500, detail=f"Error updating document: {str(e)}")
 
 
 
70
 
71
  @router.get("/document/{doc_id}", response_model=Dict)
72
  async def get_document(doc_id: str):
 
6
  import os
7
  from datetime import datetime
8
  import uuid
9
+ import tempfile
10
 
11
  router = APIRouter()
12
 
13
  BASE_URL = "https://pvanand-doc-maker.hf.space/api/v1/"
14
 
15
+ # Use system temp directory for file storage
16
+ DOCS_DIR = os.path.join(tempfile.gettempdir(), "doc_maker_documents")
17
+
18
  class DocumentPart(BaseModel):
19
  pageNo: int
20
  content: str
 
31
 
32
  def get_document_path(doc_id: str) -> str:
33
  """Get the full path for a document file"""
34
+ os.makedirs(DOCS_DIR, exist_ok=True)
35
+ return os.path.join(DOCS_DIR, f"{doc_id}.json")
36
 
37
  def update_document(doc_id: str, page_no: int, content: str) -> Dict:
38
  """Update or create document with new page content"""
 
70
  download_url=get_download_url(doc_id)
71
  )
72
  except Exception as e:
73
+ raise HTTPException(
74
+ status_code=500,
75
+ detail=f"Error updating document: {str(e)}"
76
+ )
77
 
78
  @router.get("/document/{doc_id}", response_model=Dict)
79
  async def get_document(doc_id: str):