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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -5,11 +5,14 @@ import sys
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.")
12
 
 
 
 
13
  source_path = source_img
14
  target_path = target_media
15
 
@@ -29,6 +32,7 @@ def face_swap(source_img, target_media):
29
  print(f"Running roop with args: {sys.argv}")
30
 
31
  try:
 
32
  roop_run()
33
  except SystemExit:
34
  pass
@@ -36,32 +40,39 @@ def face_swap(source_img, target_media):
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,
63
  inputs=[source_image, target_media],
64
- outputs=result_output
65
  )
66
 
67
  app.launch()
 
5
  sys.path.append('roop')
6
  from roop.core import run as roop_run
7
 
8
+ # CORE LOGIC - Ismein hum 'yield' use karenge status update ke liye
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.")
12
 
13
+ # 1. PEHLA STATUS UPDATE: Jaise hi button dabe, user ko batao
14
+ yield "Processing shuru ho gaya hai... Please wait.", None
15
+
16
  source_path = source_img
17
  target_path = target_media
18
 
 
32
  print(f"Running roop with args: {sys.argv}")
33
 
34
  try:
35
+ # 2. ASLI KAAM YAHAN HOGA (Ismein time lagega)
36
  roop_run()
37
  except SystemExit:
38
  pass
 
40
  raise gr.Error(f"Face swap fail hua. Error: {str(e)}")
41
 
42
  if not os.path.exists(output_path):
43
+ # Pehli baar model download hone par yeh message dikhega
44
+ yield "Model download ho raha hai (sirf pehli baar). Ismein 10-15 min lag sakte hain. Please sabr rakhein.", None
45
+ return # Yahan function rok dein
46
 
47
  print(f"Process poora hua. Result yahan hai: {output_path}")
 
48
 
49
+ # 3. AAKHRI STATUS UPDATE: Jab kaam poora ho jaaye
50
+ yield "✅ Process poora hua! Result taiyaar hai.", output_path
51
+
52
+ # --- Gradio UI (Dono changes ke saath) ---
53
  with gr.Blocks(theme=gr.themes.Soft()) as app:
54
+ gr.Markdown("# 🎭 Roop Face Swap AI (with Live Status)")
55
 
56
  with gr.Row():
57
  source_image = gr.Image(label="Source Face", type="filepath")
58
 
59
+ # ERROR THEEK KIYA: gr.Video se 'type="filepath"' hata diya
60
+ target_media = gr.Video(label="Target Image or Video")
61
+
62
+ # NAYA FEATURE: Status dikhane ke liye ek Textbox
63
+ status_box = gr.Textbox(label="Status", value="Ready", interactive=False)
64
 
65
  submit_btn = gr.Button("Swap Face", variant="primary")
66
 
67
+ # Result ke liye bhi gr.Video use kiya
68
  result_output = gr.Video(label="Result", interactive=False)
 
69
 
70
+ # Button click par ab 'face_swap' function chalega
71
+ # Aur woh STATUS BOX aur RESULT BOX dono ko update karega
72
  submit_btn.click(
73
  fn=face_swap,
74
  inputs=[source_image, target_media],
75
+ outputs=[status_box, result_output] # Output ab do jagah jayega
76
  )
77
 
78
  app.launch()