LapStore commited on
Commit ·
4b22123
1
Parent(s): 4b98217
modified back mGE STEP 1
Browse files
app.py
CHANGED
|
@@ -10,6 +10,8 @@ import ast
|
|
| 10 |
from server import *
|
| 11 |
import cv2
|
| 12 |
from typing import Optional
|
|
|
|
|
|
|
| 13 |
|
| 14 |
#http://localhost:8000
|
| 15 |
app = FastAPI()
|
|
@@ -38,15 +40,37 @@ async def image_step1(image_file: UploadFile = File(...),background_image: Optio
|
|
| 38 |
image = Image.open(io.BytesIO(contents_img))
|
| 39 |
|
| 40 |
|
| 41 |
-
|
|
|
|
| 42 |
|
| 43 |
# Save the processed image to a temporary file
|
| 44 |
-
output_file_path_tmp = "/tmp/tmp_processed_image.png"
|
| 45 |
-
produced_image.save(output_file_path_tmp)
|
| 46 |
|
| 47 |
# Return the processed image for download
|
| 48 |
-
return FileResponse(output_file_path_tmp, media_type='image/png', filename="/tmp/tmp_processed_image.png")
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
@app.post('/imageStep2')
|
| 52 |
async def image_step2(image_file: UploadFile = File(...),things_replace: str = Form(...), blur_radius: str = Form(...)):#--->,background_image: UploadFile = File(...)):
|
|
|
|
| 10 |
from server import *
|
| 11 |
import cv2
|
| 12 |
from typing import Optional
|
| 13 |
+
import base64
|
| 14 |
+
|
| 15 |
|
| 16 |
#http://localhost:8000
|
| 17 |
app = FastAPI()
|
|
|
|
| 40 |
image = Image.open(io.BytesIO(contents_img))
|
| 41 |
|
| 42 |
|
| 43 |
+
output_step1=SegmenterBackground().Back_step1(image,input_to_type_of_filters,int(blur_radius))
|
| 44 |
+
produced_image=output_step1[0]
|
| 45 |
|
| 46 |
# Save the processed image to a temporary file
|
| 47 |
+
#output_file_path_tmp = "/tmp/tmp_processed_image.png"
|
| 48 |
+
#produced_image.save(output_file_path_tmp)
|
| 49 |
|
| 50 |
# Return the processed image for download
|
| 51 |
+
# return FileResponse(output_file_path_tmp, media_type='image/png', filename="/tmp/tmp_processed_image.png")
|
| 52 |
+
|
| 53 |
+
'''
|
| 54 |
+
# Convert the image to base64 to return it in the response
|
| 55 |
+
buffered = io.BytesIO()
|
| 56 |
+
#image.save(buffered, format="PNG")
|
| 57 |
+
encoded_img = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 58 |
+
|
| 59 |
+
# Returning both text and the base64 image
|
| 60 |
+
return {
|
| 61 |
+
"filename": background_image.filename,
|
| 62 |
+
"message": "Image processed successfully",
|
| 63 |
+
"image_base64": encoded_img
|
| 64 |
+
}
|
| 65 |
+
'''
|
| 66 |
+
|
| 67 |
+
buffer = io.BytesIO()
|
| 68 |
+
produced_image.save(buffer, format="PNG")
|
| 69 |
+
buffer.seek(0)
|
| 70 |
+
return StreamingResponse(
|
| 71 |
+
buffer, media_type="image/png",
|
| 72 |
+
headers={"Content-Disposition": "attachment; filename=processed_image.png"}
|
| 73 |
+
)
|
| 74 |
|
| 75 |
@app.post('/imageStep2')
|
| 76 |
async def image_step2(image_file: UploadFile = File(...),things_replace: str = Form(...), blur_radius: str = Form(...)):#--->,background_image: UploadFile = File(...)):
|