Update app.py
Browse files
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 -
|
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 |
-
|
|
|
|
|
40 |
|
41 |
print(f"Process poora hua. Result yahan hai: {output_path}")
|
42 |
-
return output_path
|
43 |
|
44 |
-
#
|
|
|
|
|
|
|
45 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
46 |
-
gr.Markdown("# 🎭
|
47 |
|
48 |
with gr.Row():
|
49 |
source_image = gr.Image(label="Source Face", type="filepath")
|
50 |
|
51 |
-
#
|
52 |
-
target_media = gr.Video(label="Target Image or Video"
|
53 |
-
|
|
|
|
|
54 |
|
55 |
submit_btn = gr.Button("Swap Face", variant="primary")
|
56 |
|
57 |
-
#
|
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()
|