Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client, handle_file
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
6 |
|
7 |
def swap_face_api(source_img, target_img, doFaceEnhancer):
|
8 |
try:
|
|
|
|
|
|
|
|
|
9 |
result = client.predict(
|
10 |
source_file=handle_file(source_img),
|
11 |
target_file=handle_file(target_img),
|
@@ -15,9 +23,8 @@ def swap_face_api(source_img, target_img, doFaceEnhancer):
|
|
15 |
return result
|
16 |
except Exception as e:
|
17 |
print(f"Ошибка при вызове API: {e}")
|
18 |
-
return None
|
19 |
|
20 |
-
# Создаем интерфейс
|
21 |
iface = gr.Interface(
|
22 |
fn=swap_face_api,
|
23 |
inputs=[
|
@@ -30,4 +37,3 @@ iface = gr.Interface(
|
|
30 |
)
|
31 |
|
32 |
iface.launch()
|
33 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client, handle_file
|
3 |
+
import os
|
4 |
+
import random
|
5 |
|
6 |
+
KEYS = os.getenv("KEYS").split(",")
|
7 |
+
|
8 |
+
def get_random_api_key():
|
9 |
+
return random.choice(KEYS)
|
10 |
|
11 |
def swap_face_api(source_img, target_img, doFaceEnhancer):
|
12 |
try:
|
13 |
+
api_key = get_random_api_key()
|
14 |
+
|
15 |
+
client = Client("tuan2308/face-swap", api_key=api_key)
|
16 |
+
|
17 |
result = client.predict(
|
18 |
source_file=handle_file(source_img),
|
19 |
target_file=handle_file(target_img),
|
|
|
23 |
return result
|
24 |
except Exception as e:
|
25 |
print(f"Ошибка при вызове API: {e}")
|
26 |
+
return None
|
27 |
|
|
|
28 |
iface = gr.Interface(
|
29 |
fn=swap_face_api,
|
30 |
inputs=[
|
|
|
37 |
)
|
38 |
|
39 |
iface.launch()
|
|