Spaces:
Runtime error
Runtime error
Update main.py
Browse files
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 =
|
16 |
-
os.makedirs(NLTK_DATA_DIR, exist_ok=True)
|
17 |
-
nltk.data.path.append(NLTK_DATA_DIR)
|
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 |
|