-
Notifications
You must be signed in to change notification settings - Fork 35
Fix image processing pipeline and ChatRequest validation #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,10 +138,10 @@ async def validate_uploaded_file(file: UploadFile) -> Optional[Image.Image]: | |
| """ | ||
| return await run_in_threadpool(_validate_uploaded_file_sync, file) | ||
|
|
||
| def process_uploaded_image_sync(file: UploadFile) -> io.BytesIO: | ||
| def process_uploaded_image_sync(file: UploadFile) -> tuple[Image.Image, io.BytesIO]: | ||
| """ | ||
| Synchronously validate, resize, and strip EXIF from uploaded image. | ||
| Returns the processed image data as BytesIO. | ||
| Returns the processed PIL image and image data as BytesIO. | ||
| """ | ||
| # Check file size | ||
| file.file.seek(0, 2) | ||
|
|
@@ -187,7 +187,7 @@ def process_uploaded_image_sync(file: UploadFile) -> io.BytesIO: | |
| img_no_exif.save(output, format=fmt, quality=85) | ||
| output.seek(0) | ||
|
|
||
| return output | ||
| return img_no_exif, output | ||
|
|
||
| except Exception as pil_error: | ||
| logger.error(f"PIL processing failed: {pil_error}") | ||
|
|
@@ -202,7 +202,7 @@ def process_uploaded_image_sync(file: UploadFile) -> io.BytesIO: | |
| logger.error(f"Error processing file: {e}") | ||
| raise HTTPException(status_code=400, detail="Unable to process file.") | ||
|
|
||
| async def process_uploaded_image(file: UploadFile) -> io.BytesIO: | ||
| async def process_uploaded_image(file: UploadFile) -> tuple[Image.Image, io.BytesIO]: | ||
| return await run_in_threadpool(process_uploaded_image_sync, file) | ||
|
Comment on lines
141
to
206
|
||
|
|
||
| def save_processed_image(file_obj: io.BytesIO, path: str): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The local name
processed_imageis now anio.BytesIO(image bytes), not a PIL image. Renaming it to something likeprocessed_image_io/processed_image_byteswould make the code clearer and reduce the chance of accidentally treating it as anImage.Imagelater.