Update main.py
Browse files
main.py
CHANGED
|
@@ -4,6 +4,7 @@ import uvicorn
|
|
| 4 |
import io
|
| 5 |
import json
|
| 6 |
import os
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
import cv2
|
| 9 |
from PIL import Image
|
|
@@ -22,10 +23,8 @@ client = genai.Client(api_key=GENAI_API_KEY)
|
|
| 22 |
|
| 23 |
app = FastAPI(title="Student Result Card API")
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
if not os.path.exists(DOWNLOADS_FOLDER):
|
| 28 |
-
os.makedirs(DOWNLOADS_FOLDER)
|
| 29 |
|
| 30 |
# -----------------------------
|
| 31 |
# Preprocessing Methods
|
|
@@ -302,9 +301,9 @@ async def process_pdfs(
|
|
| 302 |
response_data = {"result_cards": student_result_cards}
|
| 303 |
|
| 304 |
if download:
|
| 305 |
-
# Create downloadable JSON file and save to
|
| 306 |
json_bytes = json.dumps(response_data, indent=2).encode("utf-8")
|
| 307 |
-
file_path = os.path.join(
|
| 308 |
with open(file_path, "wb") as f:
|
| 309 |
f.write(json_bytes)
|
| 310 |
return StreamingResponse(
|
|
@@ -324,9 +323,9 @@ async def process_pdfs(
|
|
| 324 |
@app.get("/download")
|
| 325 |
async def download_result_cards():
|
| 326 |
"""
|
| 327 |
-
Returns the previously generated result_cards.json file.
|
| 328 |
"""
|
| 329 |
-
file_path = os.path.join(
|
| 330 |
if not os.path.exists(file_path):
|
| 331 |
raise HTTPException(status_code=404, detail="File not found")
|
| 332 |
return StreamingResponse(
|
|
|
|
| 4 |
import io
|
| 5 |
import json
|
| 6 |
import os
|
| 7 |
+
import tempfile
|
| 8 |
import numpy as np
|
| 9 |
import cv2
|
| 10 |
from PIL import Image
|
|
|
|
| 23 |
|
| 24 |
app = FastAPI(title="Student Result Card API")
|
| 25 |
|
| 26 |
+
# Use the system temporary directory
|
| 27 |
+
TEMP_FOLDER = tempfile.gettempdir()
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# -----------------------------
|
| 30 |
# Preprocessing Methods
|
|
|
|
| 301 |
response_data = {"result_cards": student_result_cards}
|
| 302 |
|
| 303 |
if download:
|
| 304 |
+
# Create downloadable JSON file and save to system temp folder
|
| 305 |
json_bytes = json.dumps(response_data, indent=2).encode("utf-8")
|
| 306 |
+
file_path = os.path.join(TEMP_FOLDER, "result_cards.json")
|
| 307 |
with open(file_path, "wb") as f:
|
| 308 |
f.write(json_bytes)
|
| 309 |
return StreamingResponse(
|
|
|
|
| 323 |
@app.get("/download")
|
| 324 |
async def download_result_cards():
|
| 325 |
"""
|
| 326 |
+
Returns the previously generated result_cards.json file from the system temporary folder.
|
| 327 |
"""
|
| 328 |
+
file_path = os.path.join(TEMP_FOLDER, "result_cards.json")
|
| 329 |
if not os.path.exists(file_path):
|
| 330 |
raise HTTPException(status_code=404, detail="File not found")
|
| 331 |
return StreamingResponse(
|