Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def process_pdf(file: UploadFile = File(None)):
""" Classifies every line in the document to the logical section of the document. The logical
section can be title, author, email, section header, subsection header etc
Parameters
----------
file : File
The Bytestream of a file to be uploaded
Returns
-------
JSON
``{"labels": [(line, label)]}``
"""
global sectlabel_model
if sectlabel_model is None:
def extract_pdf(file: UploadFile = File(None)):
""" Extracts the abstract from a scholarly article
Parameters
----------
file : uploadFile
Byte Stream of a file uploaded.
Returns
-------
JSON
``{"abstract": The abstract found in the scholarly document}``
"""
global sectlabel_model
if sectlabel_model is None:
async def predict_image(model_name: str, input_data: UploadFile = File(...)):
"""
Draws bounding box(es) on image and returns it.
:param model_name: Model name
:param input_data: Image file
:return: Image file
"""
try:
output = await dl_service.run_model(model_name, input_data, draw=True, predict_batch=False)
error_logging.info('request successful;' + str(output))
return FileResponse("/main/result.jpg", media_type="image/jpg")
except ApplicationError as e:
error_logging.warning(model_name + ';' + str(e))
return ApiResponse(success=False, error=e)
except Exception as e:
error_logging.error(model_name + ' ' + str(e))
return ApiResponse(success=False, error='unexpected server error')
def pdf_pipeline(file: UploadFile = File(None)):
""" Parses the file and returns various analytics about the pdf
Parameters
----------
file: File
A File stream
Returns
-------
JSON
Returns a JSON where the key can be a section in the document with value as the text of the document.
It can also be other information such as parsed reference strings in the document, or normalised
section headers of the document. This is a feature in development. Be careful in using this.
"""
file_handle = file.file
file_name = file.filename
async def create_file(*, file: bytes = File(...)):
return {"file_size": len(file)}
def upgrade(self, file: UploadFile = File(...)):
upgrade_opsi(file, self.program.lifespan)
def predict(request: Request, img_file: bytes=File(...)):
data = {"success": False}
if request.method == "POST":
image = Image.open(io.BytesIO(img_file))
image = prepare_image(image,
(int(os.environ.get("IMAGE_WIDTH")),
int(os.environ.get("IMAGE_HEIGHT")))
)
# Ensure our NumPy array is C-contiguous as well, otherwise we won't be able to serialize it
image = image.copy(order="C")
# Generate an ID for the classification then add the classification ID + image to the queue
k = str(uuid.uuid4())
image = base64.b64encode(image).decode("utf-8")
d = {"id": k, "image": image}
def save_calibration(self, *, file: UploadFile = File(...)):
if file.content_type == "application/x-yaml":
self.program.lifespan.persist.add_calibration_file(file)
else:
json = {
"error": "Invalid calibration file",
"message": "Calibration file must be a .yaml file",
}
return JSONResponse(status_code=400, content=json)