Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
from gradio_client import Client
|
3 |
import os
|
4 |
import random
|
5 |
from io import BytesIO
|
6 |
from PIL import Image
|
|
|
7 |
|
8 |
KEYS = os.getenv("KEYS").split(",")
|
9 |
|
@@ -15,26 +16,26 @@ def swap_face_api(source_img, target_img, doFaceEnhancer):
|
|
15 |
api_key = get_random_api_key()
|
16 |
client = Client("tuan2308/face-swap")
|
17 |
|
18 |
-
# Конвертируем PIL изображения в
|
19 |
source_bytes = BytesIO()
|
20 |
-
source_img.save(source_bytes, format="JPEG")
|
21 |
-
source_bytes.
|
22 |
|
23 |
target_bytes = BytesIO()
|
24 |
-
target_img.save(target_bytes, format="JPEG")
|
25 |
-
target_bytes.
|
|
|
26 |
|
27 |
result = client.predict(
|
28 |
-
source_file=
|
29 |
-
target_file=
|
30 |
doFaceEnhancer=doFaceEnhancer,
|
31 |
api_name="/predict",
|
32 |
-
api_key=api_key
|
33 |
)
|
34 |
|
35 |
-
# Конвертируем результат из байтов
|
36 |
output_image = Image.open(BytesIO(result))
|
37 |
-
|
38 |
return output_image
|
39 |
|
40 |
except Exception as e:
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
import os
|
4 |
import random
|
5 |
from io import BytesIO
|
6 |
from PIL import Image
|
7 |
+
import base64
|
8 |
|
9 |
KEYS = os.getenv("KEYS").split(",")
|
10 |
|
|
|
16 |
api_key = get_random_api_key()
|
17 |
client = Client("tuan2308/face-swap")
|
18 |
|
19 |
+
# Конвертируем PIL изображения в байты, затем в base64
|
20 |
source_bytes = BytesIO()
|
21 |
+
source_img.save(source_bytes, format="JPEG")
|
22 |
+
source_b64 = base64.b64encode(source_bytes.getvalue()).decode("utf-8")
|
23 |
|
24 |
target_bytes = BytesIO()
|
25 |
+
target_img.save(target_bytes, format="JPEG")
|
26 |
+
target_b64 = base64.b64encode(target_bytes.getvalue()).decode("utf-8")
|
27 |
+
|
28 |
|
29 |
result = client.predict(
|
30 |
+
source_file=source_b64, # Передаем base64 строку
|
31 |
+
target_file=target_b64, # Передаем base64 строку
|
32 |
doFaceEnhancer=doFaceEnhancer,
|
33 |
api_name="/predict",
|
34 |
+
api_key=api_key # Передаем api_key в predict
|
35 |
)
|
36 |
|
37 |
+
# Конвертируем результат из байтов в PIL Image
|
38 |
output_image = Image.open(BytesIO(result))
|
|
|
39 |
return output_image
|
40 |
|
41 |
except Exception as e:
|