sandhyasinha655 commited on
Commit
914fc1a
·
verified ·
1 Parent(s): 9342563

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -3,7 +3,6 @@ import os
3
  import sys
4
  import base64
5
  import uuid
6
- from fastapi import FastAPI
7
 
8
  # --- Purana Code (Koi Change Nahi) ---
9
  sys.path.append('roop')
@@ -34,7 +33,7 @@ def face_swap_logic(source_path, target_path):
34
  return output_path
35
 
36
  # --- Gradio UI (Yeh Web Users ke liye hai) ---
37
- with gr.Blocks(theme=gr.themes.Soft()) as ui_app:
38
  gr.Markdown("# 🎭 Roop Face Swap AI")
39
  with gr.Tabs():
40
  with gr.TabItem("🖼️ Swap on Image"):
@@ -56,8 +55,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as ui_app:
56
  submit_btn_image.click(fn=web_ui_swap, inputs=[source_face_img, target_image], outputs=result_image)
57
  submit_btn_video.click(fn=web_ui_swap, inputs=[source_face_vid, target_video], outputs=result_video)
58
 
 
59
  # --- Naya API Code (Yeh Aapke Android App ke liye hai) ---
60
- app = FastAPI()
 
61
 
62
  def save_base64_to_file(b64_string, extension):
63
  filename = f"/tmp/{uuid.uuid4().hex}.{extension}"
@@ -65,7 +66,7 @@ def save_base64_to_file(b64_string, extension):
65
  f.write(base64.b64decode(b64_string))
66
  return filename
67
 
68
- @app.post("/api/swap-face")
69
  async def api_face_swap(payload: dict):
70
  source_b64 = payload.get("source_face_b64")
71
  target_b64 = payload.get("target_media_b64")
@@ -91,8 +92,5 @@ async def api_face_swap(payload: dict):
91
  else:
92
  return {"error": "Face swap fail hua."}
93
 
94
- # ===== YAHAN MERI GALTI THI, AB THEEK HAI =====
95
- # OLD: app = gr.mount_app(app, ui_app, path="/")
96
- # NEW: Sahi function ka naam 'mount_gradio_app' hai
97
- app = gr.mount_gradio_app(app, ui_app, path="/")
98
- # ===============================================
 
3
  import sys
4
  import base64
5
  import uuid
 
6
 
7
  # --- Purana Code (Koi Change Nahi) ---
8
  sys.path.append('roop')
 
33
  return output_path
34
 
35
  # --- Gradio UI (Yeh Web Users ke liye hai) ---
36
+ with gr.Blocks(theme=gr.themes.Soft()) as app: # Yahan 'app' ek Gradio Blocks object hai
37
  gr.Markdown("# 🎭 Roop Face Swap AI")
38
  with gr.Tabs():
39
  with gr.TabItem("🖼️ Swap on Image"):
 
55
  submit_btn_image.click(fn=web_ui_swap, inputs=[source_face_img, target_image], outputs=result_image)
56
  submit_btn_video.click(fn=web_ui_swap, inputs=[source_face_vid, target_video], outputs=result_video)
57
 
58
+
59
  # --- Naya API Code (Yeh Aapke Android App ke liye hai) ---
60
+ # Hum FastAPI ko alag se banane ke bajaye, seedha Gradio ke chalte hue server (app.app) mein hi apna API endpoint jod denge.
61
+ # Yeh sabse saaf aur sahi tarika hai.
62
 
63
  def save_base64_to_file(b64_string, extension):
64
  filename = f"/tmp/{uuid.uuid4().hex}.{extension}"
 
66
  f.write(base64.b64decode(b64_string))
67
  return filename
68
 
69
+ @app.post("/api/swap-face") # Yahan 'app' Gradio ka Blocks object hai
70
  async def api_face_swap(payload: dict):
71
  source_b64 = payload.get("source_face_b64")
72
  target_b64 = payload.get("target_media_b64")
 
92
  else:
93
  return {"error": "Face swap fail hua."}
94
 
95
+ # AAKHRI AUR SABSE ZAROORI LINE - APP KO LAUNCH KARNA
96
+ app.launch()