Ashrafb commited on
Commit
6327122
·
verified ·
1 Parent(s): c19bd3b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -10
main.py CHANGED
@@ -17,7 +17,16 @@ def load_model():
17
  global model
18
  from vtoonify_model import Model
19
  model = Model(device='cuda' if torch.cuda.is_available() else 'cpu')
20
- model.load_model('cartoon1')
 
 
 
 
 
 
 
 
 
21
 
22
  @app.post("/upload/")
23
  async def process_image(file: UploadFile = File(...), top: int = Form(...), bottom: int = Form(...), left: int = Form(...), right: int = Form(...)):
@@ -34,7 +43,7 @@ async def process_image(file: UploadFile = File(...), top: int = Form(...), bott
34
 
35
  # Process the uploaded image
36
  aligned_face, instyle, message = model.detect_and_align_image(frame_rgb, top, bottom, left, right)
37
- processed_image, message = model.image_toonify(aligned_face, instyle, model.exstyle, style_degree=0.5, style_type='cartoon1')
38
 
39
  # Convert BGR to RGB
40
  processed_image_rgb = cv2.cvtColor(processed_image, cv2.COLOR_BGR2RGB)
@@ -46,11 +55,3 @@ async def process_image(file: UploadFile = File(...), top: int = Form(...), bott
46
  return StreamingResponse(BytesIO(encoded_image.tobytes()), media_type="image/jpeg")
47
 
48
 
49
- # Mount static files directory
50
- app.mount("/", StaticFiles(directory="AB", html=True), name="static")
51
-
52
- # Define index route
53
- @app.get("/")
54
- def index():
55
- return FileResponse(path="/app/AB/index.html", media_type="text/html")
56
-
 
17
  global model
18
  from vtoonify_model import Model
19
  model = Model(device='cuda' if torch.cuda.is_available() else 'cpu')
20
+ model.load_model('cartoon1-d')
21
+ from fastapi.middleware.cors import CORSMiddleware
22
+
23
+ app.add_middleware(
24
+ CORSMiddleware,
25
+ allow_origins=["*"], # Adjust as needed, '*' allows requests from any origin
26
+ allow_credentials=True,
27
+ allow_methods=["*"],
28
+ allow_headers=["*"],
29
+ )
30
 
31
  @app.post("/upload/")
32
  async def process_image(file: UploadFile = File(...), top: int = Form(...), bottom: int = Form(...), left: int = Form(...), right: int = Form(...)):
 
43
 
44
  # Process the uploaded image
45
  aligned_face, instyle, message = model.detect_and_align_image(frame_rgb, top, bottom, left, right)
46
+ processed_image, message = model.image_toonify(aligned_face, instyle, model.exstyle, style_degree=0.5, style_type='cartoon1-d')
47
 
48
  # Convert BGR to RGB
49
  processed_image_rgb = cv2.cvtColor(processed_image, cv2.COLOR_BGR2RGB)
 
55
  return StreamingResponse(BytesIO(encoded_image.tobytes()), media_type="image/jpeg")
56
 
57