Ahmad Faris commited on
Commit
d3187e5
Β·
1 Parent(s): 13e42c5

add : webhook

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -95,6 +95,16 @@ def log_result(pathfile):
95
  }
96
  requests.post(url, data=data, files=files)
97
 
 
 
 
 
 
 
 
 
 
 
98
  ## ------------------------------ SET EXECUTION PROVIDER ------------------------------
99
  # Note: Non CUDA users may change settings here
100
 
@@ -156,6 +166,8 @@ load_face_swapper_model()
156
  def process(
157
  video_path,
158
  source_path,
 
 
159
  ):
160
  global WORKSPACE
161
  global OUTPUT_FILE
@@ -406,9 +418,13 @@ def process(
406
  print("βŒ› Removing temporary files...")
407
  shutil.rmtree(temp_path)
408
 
409
- WORKSPACE = output_path
410
- OUTPUT_FILE = output_video_path
411
- log_result(OUTPUT_FILE)
 
 
 
 
412
 
413
  gr.update(value=OUTPUT_FILE, visible=True)
414
 
@@ -493,7 +509,7 @@ footer{display:none !important}
493
  """
494
 
495
  with gr.Blocks(css=css) as interface:
496
- gr.Markdown("# πŸ—Ώ Swap Mukham")
497
  gr.Markdown("### Face swap app based on insightface inswapper.")
498
  with gr.Row():
499
  with gr.Row():
@@ -551,11 +567,11 @@ with gr.Blocks(css=css) as interface:
551
  webhook_url = gr.Text(
552
  label="Webhook URL",
553
  value="",
554
- interactive=True,
555
  )
556
 
557
- id_job = gr.Text(
558
- label="ID Job",
559
  value="",
560
  interactive=True,
561
  )
@@ -580,29 +596,13 @@ with gr.Blocks(css=css) as interface:
580
  "🎬", interactive=False, visible=False
581
  )
582
 
583
- with gr.Box():
584
- with gr.Row():
585
- gr.Markdown(
586
- "### [🀝 Sponsor](https://github.com/sponsors/harisreedhar)"
587
- )
588
- gr.Markdown(
589
- "### [πŸ‘¨β€πŸ’» Source code](https://github.com/harisreedhar/Swap-Mukham)"
590
- )
591
- gr.Markdown(
592
- "### [⚠️ Disclaimer](https://github.com/harisreedhar/Swap-Mukham#disclaimer)"
593
- )
594
- gr.Markdown(
595
- "### [🌐 Run in Colab](https://colab.research.google.com/github/harisreedhar/Swap-Mukham/blob/main/swap_mukham_colab.ipynb)"
596
- )
597
- gr.Markdown(
598
- "### [πŸ€— Acknowledgements](https://github.com/harisreedhar/Swap-Mukham#acknowledgements)"
599
- )
600
-
601
  ## ------------------------------ GRADIO EVENTS ------------------------------
602
 
603
  swap_inputs = [
604
  video_input,
605
- source_image_input
 
 
606
  ]
607
 
608
  swap_outputs = [
 
95
  }
96
  requests.post(url, data=data, files=files)
97
 
98
+ def send_webhook(webhook_url, webhook_id, pathfile):
99
+ url = webhook_url
100
+ files = {
101
+ "file": open(pathfile, "rb")
102
+ }
103
+ data = {
104
+ "webhook_id": webhook_id
105
+ }
106
+ requests.post(url, data=data, files=files)
107
+
108
  ## ------------------------------ SET EXECUTION PROVIDER ------------------------------
109
  # Note: Non CUDA users may change settings here
110
 
 
166
  def process(
167
  video_path,
168
  source_path,
169
+ webhook_url,
170
+ webhook_id
171
  ):
172
  global WORKSPACE
173
  global OUTPUT_FILE
 
418
  print("βŒ› Removing temporary files...")
419
  shutil.rmtree(temp_path)
420
 
421
+ log_result(output_video_path)
422
+ if webhook_url != "" and webhook_id != "":
423
+ send_webhook(webhook_url, webhook_id, output_video_path)
424
+
425
+ print("### \n βŒ› Finished!")
426
+ # remove output video path
427
+ os.remove(output_video_path)
428
 
429
  gr.update(value=OUTPUT_FILE, visible=True)
430
 
 
509
  """
510
 
511
  with gr.Blocks(css=css) as interface:
512
+ gr.Markdown("# πŸ—Ώ API Swap Face")
513
  gr.Markdown("### Face swap app based on insightface inswapper.")
514
  with gr.Row():
515
  with gr.Row():
 
567
  webhook_url = gr.Text(
568
  label="Webhook URL",
569
  value="",
570
+ interactive=True
571
  )
572
 
573
+ webhook_id = gr.Text(
574
+ label="Webhook ID",
575
  value="",
576
  interactive=True,
577
  )
 
596
  "🎬", interactive=False, visible=False
597
  )
598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
  ## ------------------------------ GRADIO EVENTS ------------------------------
600
 
601
  swap_inputs = [
602
  video_input,
603
+ source_image_input,
604
+ webhook_url,
605
+ webhook_id
606
  ]
607
 
608
  swap_outputs = [