Update app.py
Browse files
app.py
CHANGED
@@ -2,13 +2,10 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import sys
|
4 |
|
5 |
-
#
|
6 |
-
# Hum 'roop' folder ko system path mein add kar rahe hain taaki Python use dhoondh sake.
|
7 |
sys.path.append('roop')
|
8 |
|
9 |
-
#
|
10 |
-
# 'roop' folder ke andar 'core.py' file se 'run' function ko import kar rahe hain.
|
11 |
-
# Yahi aapke Colab ke video wale code ka logic hai.
|
12 |
from roop.core import run as roop_run
|
13 |
|
14 |
# --- Gradio Function ---
|
@@ -16,24 +13,26 @@ def face_swap(source_img, target_media):
|
|
16 |
if source_img is None or target_media is None:
|
17 |
raise gr.Error("Please upload both source image and target media.")
|
18 |
|
19 |
-
#
|
20 |
-
source_path = source_img.name
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
# Output file ka naam tay karna
|
24 |
output_filename = os.path.basename(target_path)
|
25 |
-
# Output folder banayein agar nahi hai
|
26 |
os.makedirs("output", exist_ok=True)
|
27 |
output_path = os.path.join("output", f"result_{output_filename}")
|
28 |
|
29 |
# Roop ko chalane ke liye arguments set karna
|
30 |
args = [
|
31 |
-
"run.py",
|
32 |
"--source", source_path,
|
33 |
"--target", target_path,
|
34 |
"--output", output_path,
|
35 |
-
"--execution-provider", "cpu",
|
36 |
-
"-e"
|
37 |
]
|
38 |
sys.argv = args
|
39 |
|
@@ -43,6 +42,7 @@ def face_swap(source_img, target_media):
|
|
43 |
try:
|
44 |
roop_run()
|
45 |
except Exception as e:
|
|
|
46 |
raise gr.Error(f"Face swap failed. Error: {str(e)}")
|
47 |
|
48 |
print(f"Processing complete. Result at: {output_path}")
|
@@ -71,5 +71,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
71 |
gr.Markdown("---")
|
72 |
gr.Markdown("Created with help from AI. Make sure to use this tool responsibly.")
|
73 |
|
74 |
-
# App ko launch karein
|
75 |
app.launch()
|
|
|
2 |
import os
|
3 |
import sys
|
4 |
|
5 |
+
# roop folder ko system path mein add karna
|
|
|
6 |
sys.path.append('roop')
|
7 |
|
8 |
+
# Sahi jagah se function import karna
|
|
|
|
|
9 |
from roop.core import run as roop_run
|
10 |
|
11 |
# --- Gradio Function ---
|
|
|
13 |
if source_img is None or target_media is None:
|
14 |
raise gr.Error("Please upload both source image and target media.")
|
15 |
|
16 |
+
# ===== YAHAN MERI GALTI THI, AB THEEK HAI =====
|
17 |
+
# OLD: source_path = source_img.name
|
18 |
+
# NEW: Gradio 'filepath' type mein seedha path (string) deta hai.
|
19 |
+
source_path = source_img
|
20 |
+
target_path = target_media
|
21 |
+
# ===============================================
|
22 |
|
23 |
# Output file ka naam tay karna
|
24 |
output_filename = os.path.basename(target_path)
|
|
|
25 |
os.makedirs("output", exist_ok=True)
|
26 |
output_path = os.path.join("output", f"result_{output_filename}")
|
27 |
|
28 |
# Roop ko chalane ke liye arguments set karna
|
29 |
args = [
|
30 |
+
"run.py",
|
31 |
"--source", source_path,
|
32 |
"--target", target_path,
|
33 |
"--output", output_path,
|
34 |
+
"--execution-provider", "cpu",
|
35 |
+
"-e"
|
36 |
]
|
37 |
sys.argv = args
|
38 |
|
|
|
42 |
try:
|
43 |
roop_run()
|
44 |
except Exception as e:
|
45 |
+
# Error aane par user ko message dikhana
|
46 |
raise gr.Error(f"Face swap failed. Error: {str(e)}")
|
47 |
|
48 |
print(f"Processing complete. Result at: {output_path}")
|
|
|
71 |
gr.Markdown("---")
|
72 |
gr.Markdown("Created with help from AI. Make sure to use this tool responsibly.")
|
73 |
|
|
|
74 |
app.launch()
|