sandhyasinha655 commited on
Commit
678de96
·
verified ·
1 Parent(s): e359100

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -5,6 +5,7 @@ import sys
5
  sys.path.append('roop')
6
  from roop.core import run as roop_run
7
 
 
8
  def face_swap(source_img, target_media):
9
  if source_img is None or target_media is None:
10
  raise gr.Error("Dono file upload karein.")
@@ -16,8 +17,6 @@ def face_swap(source_img, target_media):
16
  os.makedirs("output", exist_ok=True)
17
  output_path = os.path.join("output", f"result_{output_filename}")
18
 
19
- # ===== KOI EXTRA LOGIC NAHI, SIMPLE SWAP =====
20
- # Face Enhancer wala argument hata diya hai.
21
  args = [
22
  "run.py",
23
  "--source", source_path,
@@ -25,7 +24,6 @@ def face_swap(source_img, target_media):
25
  "--output", output_path,
26
  "--execution-provider", "cpu",
27
  ]
28
- # ============================================
29
  sys.argv = args
30
 
31
  print(f"Running roop with args: {sys.argv}")
@@ -33,29 +31,32 @@ def face_swap(source_img, target_media):
33
  try:
34
  roop_run()
35
  except SystemExit:
36
- # Roop argparse error par SystemExit deta hai, use pass kar rahe hain.
37
  pass
38
  except Exception as e:
39
  raise gr.Error(f"Face swap fail hua. Error: {str(e)}")
40
 
41
- # Check karein ki output file bani hai ya nahi
42
  if not os.path.exists(output_path):
43
- # Agar file nahi bani to user ko batayein ki model download ho raha hai
44
- # Pehli baar run hone mein 5-10 min lag sakte hain.
45
- raise gr.Error("Processing ho raha hai... Pehli baar run hone mein 10-15 minute lag sakte hain kyunki model download ho raha hai. Please sabr rakhein aur thodi der baad dobara try karein.")
46
 
47
  print(f"Process poora hua. Result yahan hai: {output_path}")
48
  return output_path
49
 
 
50
  with gr.Blocks(theme=gr.themes.Soft()) as app:
51
  gr.Markdown("# 🎭 Simple Face Swap (Colab Port)")
52
 
53
  with gr.Row():
54
  source_image = gr.Image(label="Source Face", type="filepath")
55
- target_media = gr.File(label="Target Image or Video", type="filepath")
 
 
 
56
 
57
  submit_btn = gr.Button("Swap Face", variant="primary")
58
- result_output = gr.File(label="Result", interactive=False)
 
 
 
59
 
60
  submit_btn.click(
61
  fn=face_swap,
 
5
  sys.path.append('roop')
6
  from roop.core import run as roop_run
7
 
8
+ # CORE LOGIC - ISMEIN KOI CHANGE NAHI HAI
9
  def face_swap(source_img, target_media):
10
  if source_img is None or target_media is None:
11
  raise gr.Error("Dono file upload karein.")
 
17
  os.makedirs("output", exist_ok=True)
18
  output_path = os.path.join("output", f"result_{output_filename}")
19
 
 
 
20
  args = [
21
  "run.py",
22
  "--source", source_path,
 
24
  "--output", output_path,
25
  "--execution-provider", "cpu",
26
  ]
 
27
  sys.argv = args
28
 
29
  print(f"Running roop with args: {sys.argv}")
 
31
  try:
32
  roop_run()
33
  except SystemExit:
 
34
  pass
35
  except Exception as e:
36
  raise gr.Error(f"Face swap fail hua. Error: {str(e)}")
37
 
 
38
  if not os.path.exists(output_path):
39
+ raise gr.Error("Processing ho raha hai... Pehli baar run hone mein 10-15 minute lag sakte hain. Please sabr rakhein.")
 
 
40
 
41
  print(f"Process poora hua. Result yahan hai: {output_path}")
42
  return output_path
43
 
44
+ # --- Gradio UI (SIRF YAHAN CHANGE HUA HAI) ---
45
  with gr.Blocks(theme=gr.themes.Soft()) as app:
46
  gr.Markdown("# 🎭 Simple Face Swap (Colab Port)")
47
 
48
  with gr.Row():
49
  source_image = gr.Image(label="Source Face", type="filepath")
50
+
51
+ # ===== CHANGE 1: gr.File ko gr.Video se badla =====
52
+ target_media = gr.Video(label="Target Image or Video", type="filepath")
53
+ # ==================================================
54
 
55
  submit_btn = gr.Button("Swap Face", variant="primary")
56
+
57
+ # ===== CHANGE 2: Result ke liye bhi gr.Video use kiya taaki result ka bhi preview dikhe =====
58
+ result_output = gr.Video(label="Result", interactive=False)
59
+ # ======================================================================================
60
 
61
  submit_btn.click(
62
  fn=face_swap,