pvanand commited on
Commit
4bb4b7e
·
verified ·
1 Parent(s): fc91ec9

Update doc_maker.py

Browse files
Files changed (1) hide show
  1. doc_maker.py +4 -8
doc_maker.py CHANGED
@@ -8,11 +8,9 @@ from datetime import datetime
8
  import uuid
9
  import tempfile
10
 
11
- router = APIRouter(prefix="/api/v1")
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):
@@ -27,15 +25,13 @@ class DocumentResponse(BaseModel):
27
  download_url: Optional[str] = None
28
 
29
  def get_download_url(file_id: str) -> str:
30
- return f"{BASE_URL}download/{file_id}"
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"""
39
  filepath = get_document_path(doc_id)
40
 
41
  if os.path.exists(filepath):
@@ -75,7 +71,7 @@ async def add_document_part(part: DocumentPart):
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):
80
  filepath = get_document_path(doc_id)
81
  if not os.path.exists(filepath):
 
8
  import uuid
9
  import tempfile
10
 
11
+ router = APIRouter() # Add prefix here
12
 
13
+ BASE_URL = "https://pvanand-doc-maker.hf.space/api/v1"
 
 
14
  DOCS_DIR = os.path.join(tempfile.gettempdir(), "doc_maker_documents")
15
 
16
  class DocumentPart(BaseModel):
 
25
  download_url: Optional[str] = None
26
 
27
  def get_download_url(file_id: str) -> str:
28
+ return f"{BASE_URL}/download/{file_id}"
29
 
30
  def get_document_path(doc_id: str) -> str:
 
31
  os.makedirs(DOCS_DIR, exist_ok=True)
32
  return os.path.join(DOCS_DIR, f"{doc_id}.json")
33
 
34
  def update_document(doc_id: str, page_no: int, content: str) -> Dict:
 
35
  filepath = get_document_path(doc_id)
36
 
37
  if os.path.exists(filepath):
 
71
  detail=f"Error updating document: {str(e)}"
72
  )
73
 
74
+ @router.get("/document/{doc_id}")
75
  async def get_document(doc_id: str):
76
  filepath = get_document_path(doc_id)
77
  if not os.path.exists(filepath):