samyak152002 commited on
Commit
1e01eb5
1 Parent(s): 798ad42

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +12 -2
app/main.py CHANGED
@@ -3,8 +3,13 @@ from fastapi import FastAPI, File, UploadFile, HTTPException
3
  from fastapi.responses import JSONResponse
4
  from typing import Dict, Any
5
  import io
6
- import base64 # Import base64 for encoding
7
- from .annotations import analyze_pdf # Use relative import
 
 
 
 
 
8
 
9
  app = FastAPI(
10
  title="PDF Language Issue Analyzer",
@@ -17,6 +22,7 @@ def read_root():
17
  """
18
  Root endpoint to verify that the API is running.
19
  """
 
20
  return {"message": "PDF Language Issue Analyzer API is running."}
21
 
22
  @app.post("/analyze", summary="Analyze PDF for Language Issues")
@@ -27,6 +33,7 @@ async def analyze_pdf_endpoint(file: UploadFile = File(...)):
27
  - **file**: PDF file to be analyzed.
28
  """
29
  if file.content_type != "application/pdf":
 
30
  raise HTTPException(status_code=400, detail="Invalid file type. Only PDFs are supported.")
31
 
32
  try:
@@ -42,7 +49,10 @@ async def analyze_pdf_endpoint(file: UploadFile = File(...)):
42
  # Properly encode the annotated PDF in Base64
43
  encoded_pdf = base64.b64encode(annotated_pdf).decode('utf-8')
44
  response["annotated_pdf"] = f"data:application/pdf;base64,{encoded_pdf}"
 
45
 
 
46
  return JSONResponse(content=response)
47
  except Exception as e:
 
48
  raise HTTPException(status_code=500, detail=str(e))
 
3
  from fastapi.responses import JSONResponse
4
  from typing import Dict, Any
5
  import io
6
+ import base64
7
+ import logging
8
+ from .annotations import analyze_pdf
9
+
10
+ # Configure logging
11
+ logging.basicConfig(level=logging.INFO)
12
+ logger = logging.getLogger(__name__)
13
 
14
  app = FastAPI(
15
  title="PDF Language Issue Analyzer",
 
22
  """
23
  Root endpoint to verify that the API is running.
24
  """
25
+ logger.info("Root endpoint accessed.")
26
  return {"message": "PDF Language Issue Analyzer API is running."}
27
 
28
  @app.post("/analyze", summary="Analyze PDF for Language Issues")
 
33
  - **file**: PDF file to be analyzed.
34
  """
35
  if file.content_type != "application/pdf":
36
+ logger.error("Invalid file type uploaded: %s", file.content_type)
37
  raise HTTPException(status_code=400, detail="Invalid file type. Only PDFs are supported.")
38
 
39
  try:
 
49
  # Properly encode the annotated PDF in Base64
50
  encoded_pdf = base64.b64encode(annotated_pdf).decode('utf-8')
51
  response["annotated_pdf"] = f"data:application/pdf;base64,{encoded_pdf}"
52
+ logger.info("Annotated PDF generated and encoded.")
53
 
54
+ logger.info("PDF analysis completed successfully.")
55
  return JSONResponse(content=response)
56
  except Exception as e:
57
+ logger.exception("Error occurred during PDF analysis.")
58
  raise HTTPException(status_code=500, detail=str(e))