tuan2308 commited on
Commit
3aff737
1 Parent(s): 42b1f81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -12,11 +12,16 @@ from roop.utilities import normalize_output_path
12
  import os
13
  from PIL import Image
14
  import spaces
 
15
 
16
  @spaces.GPU
17
  def swap_face(source_file, target_file, doFaceEnhancer):
18
- source_path = "input.jpg"
19
- target_path = "target.jpg"
 
 
 
 
20
 
21
  source_image = Image.fromarray(source_file)
22
  source_image.save(source_path)
@@ -26,7 +31,7 @@ def swap_face(source_file, target_file, doFaceEnhancer):
26
  print("source_path: ", source_path)
27
  print("target_path: ", target_path)
28
 
29
- output_path = "output.jpg"
30
  normalized_output_path = normalize_output_path(source_path, target_path, output_path)
31
 
32
  frame_processors = ["face_swapper", "face_enhancer"] if doFaceEnhancer else ["face_swapper"]
 
12
  import os
13
  from PIL import Image
14
  import spaces
15
+ import uuid
16
 
17
  @spaces.GPU
18
  def swap_face(source_file, target_file, doFaceEnhancer):
19
+ session_id = str(uuid.uuid4()) # Tạo một UUID duy nhất cho mỗi phiên làm việc
20
+ session_dir = f"temp/{session_id}"
21
+ os.makedirs(session_dir, exist_ok=True)
22
+
23
+ source_path = os.path.join(session_dir, "input.jpg")
24
+ target_path = os.path.join(session_dir, "target.jpg")
25
 
26
  source_image = Image.fromarray(source_file)
27
  source_image.save(source_path)
 
31
  print("source_path: ", source_path)
32
  print("target_path: ", target_path)
33
 
34
+ output_path = os.path.join(session_dir, "output.jpg")
35
  normalized_output_path = normalize_output_path(source_path, target_path, output_path)
36
 
37
  frame_processors = ["face_swapper", "face_enhancer"] if doFaceEnhancer else ["face_swapper"]