Spaces:
Running
Running
Ahmad Faris
commited on
Commit
Β·
d3187e5
1
Parent(s):
13e42c5
add : webhook
Browse files
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 |
-
|
| 410 |
-
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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 |
-
|
| 558 |
-
label="ID
|
| 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 = [
|