Delete main.py
Browse files
main.py
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 2 |
-
from fastapi.responses import FileResponse
|
| 3 |
-
import cv2
|
| 4 |
-
import shutil
|
| 5 |
-
from model import Model # Import your model class here
|
| 6 |
-
|
| 7 |
-
app = FastAPI()
|
| 8 |
-
model = Model(device='cpu') # Initialize your model with the appropriate device
|
| 9 |
-
|
| 10 |
-
@app.post("/upload/")
|
| 11 |
-
async def process_image(file: UploadFile = File(...), top: int = Form(...), bottom: int = Form(...), left: int = Form(...), right: int = Form(...)):
|
| 12 |
-
# Save the uploaded image locally
|
| 13 |
-
with open("uploaded_image.jpg", "wb") as buffer:
|
| 14 |
-
shutil.copyfileobj(file.file, buffer)
|
| 15 |
-
|
| 16 |
-
# Load the model (assuming 'cartoon1' is always used)
|
| 17 |
-
exstyle, load_info = model.load_model('cartoon1')
|
| 18 |
-
|
| 19 |
-
# Process the uploaded image
|
| 20 |
-
# Replace these values with the actual bounding box coordinates
|
| 21 |
-
aligned_face, instyle, message = model.detect_and_align_image("uploaded_image.jpg", top, bottom, left, right)
|
| 22 |
-
|
| 23 |
-
# Process the aligned face further if needed
|
| 24 |
-
# For example, you can pass it to the image_toonify method
|
| 25 |
-
style_degree = 0.5
|
| 26 |
-
style_type = 'cartoon1' # Adjust this based on the actual style type
|
| 27 |
-
result_image, message = model.image_toonify(aligned_face, instyle, exstyle, style_degree, style_type)
|
| 28 |
-
|
| 29 |
-
# Save the result image locally
|
| 30 |
-
result_image_path = "result_image.jpg"
|
| 31 |
-
cv2.imwrite(result_image_path, result_image)
|
| 32 |
-
|
| 33 |
-
# Return the processed image
|
| 34 |
-
return FileResponse(result_image_path, media_type="image/jpeg", headers={"Content-Disposition": "attachment; filename=result_image.jpg"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|