samyak152002 commited on
Commit
d7adeec
·
verified ·
1 Parent(s): 3f15597

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +6 -3
app/main.py CHANGED
@@ -1,9 +1,10 @@
1
  # main.py
2
  from fastapi import FastAPI, File, UploadFile, HTTPException
3
- from fastapi.responses import JSONResponse, StreamingResponse
4
  from typing import Dict, Any
5
  import io
6
- from annotations import analyze_pdf
 
7
 
8
  app = FastAPI(
9
  title="PDF Language Issue Analyzer",
@@ -31,7 +32,9 @@ async def analyze_pdf_endpoint(file: UploadFile = File(...)):
31
  }
32
 
33
  if annotated_pdf:
34
- response["annotated_pdf"] = "data:application/pdf;base64," + io.BytesIO(annotated_pdf).getvalue().decode('latin1') # Adjust encoding as needed
 
 
35
 
36
  return JSONResponse(content=response)
37
  except Exception as e:
 
1
  # main.py
2
  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",
 
32
  }
33
 
34
  if annotated_pdf:
35
+ # Properly encode the annotated PDF in Base64
36
+ encoded_pdf = base64.b64encode(annotated_pdf).decode('utf-8')
37
+ response["annotated_pdf"] = f"data:application/pdf;base64,{encoded_pdf}"
38
 
39
  return JSONResponse(content=response)
40
  except Exception as e: