Ashrafb commited on
Commit
8c18f47
·
verified ·
1 Parent(s): d6cf74f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -3
main.py CHANGED
@@ -190,13 +190,13 @@ async def process_image(file: UploadFile = File(...), top: int = Form(...), bott
190
  if model is None:
191
  return {"error": "Model not loaded."}
192
 
193
- # Save the uploaded image locally
194
- with open("uploaded_image.jpg", "wb") as buffer:
195
  shutil.copyfileobj(file.file, buffer)
196
 
197
  # Process the uploaded image
198
  # Load the image and convert it from BGR to RGB
199
- frame = cv2.imread("uploaded_image.jpg")
200
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
201
  aligned_face, instyle, message = model.detect_and_align_image(frame, top, bottom, left, right)
202
  processed_image, message = model.image_toonify(aligned_face, instyle, model.exstyle, style_degree=0.5, style_type='cartoon1')
 
190
  if model is None:
191
  return {"error": "Model not loaded."}
192
 
193
+ # Save the uploaded image locally with its original filename
194
+ with open(file.filename, "wb") as buffer:
195
  shutil.copyfileobj(file.file, buffer)
196
 
197
  # Process the uploaded image
198
  # Load the image and convert it from BGR to RGB
199
+ frame = cv2.imread(file.filename)
200
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
201
  aligned_face, instyle, message = model.detect_and_align_image(frame, top, bottom, left, right)
202
  processed_image, message = model.image_toonify(aligned_face, instyle, model.exstyle, style_degree=0.5, style_type='cartoon1')