hariharan220 commited on
Commit
fcb38b7
Β·
verified Β·
1 Parent(s): 0febcb8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -4
main.py CHANGED
@@ -12,10 +12,11 @@ from fastapi import FastAPI, File, UploadFile, HTTPException
12
  from fastapi.middleware.cors import CORSMiddleware
13
 
14
  # βœ… Ensure NLTK Dependencies are Stored in a Writable Directory
15
- NLTK_DATA_DIR = os.path.join(os.getcwd(), "nltk_data")
16
- os.makedirs(NLTK_DATA_DIR, exist_ok=True) # Ensure the directory exists
17
- nltk.data.path.append(NLTK_DATA_DIR) # Set the download path
18
 
 
19
  try:
20
  nltk.data.find("tokenizers/punkt")
21
  except LookupError:
@@ -74,7 +75,7 @@ async def summarize_pdf(file: UploadFile = File(...)):
74
  try:
75
  start_time = time.time()
76
  pdf_content = await file.read()
77
- pdf_path = "temp.pdf"
78
  with open(pdf_path, "wb") as f:
79
  f.write(pdf_content)
80
 
 
12
  from fastapi.middleware.cors import CORSMiddleware
13
 
14
  # βœ… Ensure NLTK Dependencies are Stored in a Writable Directory
15
+ NLTK_DATA_DIR = "/tmp/nltk_data" # βœ… Store in /tmp/ (writable in Hugging Face Spaces)
16
+ os.makedirs(NLTK_DATA_DIR, exist_ok=True)
17
+ nltk.data.path.append(NLTK_DATA_DIR)
18
 
19
+ # βœ… Download punkt tokenizer
20
  try:
21
  nltk.data.find("tokenizers/punkt")
22
  except LookupError:
 
75
  try:
76
  start_time = time.time()
77
  pdf_content = await file.read()
78
+ pdf_path = "/tmp/temp.pdf" # βœ… Store in /tmp/
79
  with open(pdf_path, "wb") as f:
80
  f.write(pdf_content)
81