Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import torch
import numpy as np
import os
import uuid

# Existing imports
import numpy as np
Expand Down Expand Up @@ -65,11 +66,13 @@ class ProcessResponse(BaseModel):
parsed_content_list: str
label_coordinates: str

def generate_uuid():
return str(uuid.uuid4())

def process(
image_input: Image.Image, box_threshold: float, iou_threshold: float
) -> ProcessResponse:
image_save_path = "imgs/saved_image_demo.png"
image_save_path = f"imgs/{generate_uuid()}.png"
image_input.save(image_save_path)
image = Image.open(image_save_path)
box_overlay_ratio = image.size[0] / 3200
Expand Down Expand Up @@ -109,6 +112,8 @@ def process(
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")

os.remove(image_save_path)

return ProcessResponse(
image=img_str,
parsed_content_list=str(parsed_content_list_str),
Expand Down