Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -7,9 +7,11 @@ from huggingface_hub import create_repo, upload_file
|
|
| 7 |
app = Flask(__name__)
|
| 8 |
|
| 9 |
# Função para chamar a API de hospedagem de imagens
|
| 10 |
-
def host_image(
|
| 11 |
-
api_url = "https://wosocial.bubbleapps.io/version-test/api/1.1/wf/save
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
if response.status_code == 200:
|
| 14 |
return response.json()["response"]["result"]
|
| 15 |
else:
|
|
@@ -93,11 +95,16 @@ def faceswapper():
|
|
| 93 |
user_photo = request.args.get('user_photo', default='')
|
| 94 |
result_photo = request.args.get('result_photo', default='')
|
| 95 |
|
| 96 |
-
#
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
# Hospedar a imagem e obter a URL
|
| 100 |
-
hosted_url = host_image(
|
| 101 |
|
| 102 |
if hosted_url:
|
| 103 |
return jsonify({"result_url": hosted_url})
|
|
|
|
| 7 |
app = Flask(__name__)
|
| 8 |
|
| 9 |
# Função para chamar a API de hospedagem de imagens
|
| 10 |
+
def host_image(endpoint, image_path):
|
| 11 |
+
api_url = "https://wosocial.bubbleapps.io/version-test/api/1.1/wf/save"
|
| 12 |
+
image_url = f"{endpoint}/file={image_path}"
|
| 13 |
+
files = {'file': open(image_url, 'rb')}
|
| 14 |
+
response = requests.post(api_url, files=files)
|
| 15 |
if response.status_code == 200:
|
| 16 |
return response.json()["response"]["result"]
|
| 17 |
else:
|
|
|
|
| 95 |
user_photo = request.args.get('user_photo', default='')
|
| 96 |
result_photo = request.args.get('result_photo', default='')
|
| 97 |
|
| 98 |
+
# Chamar a API Gradio
|
| 99 |
+
client = Client(endpoint, upload_files=True)
|
| 100 |
+
result_path = client.predict(
|
| 101 |
+
user_photo,
|
| 102 |
+
result_photo,
|
| 103 |
+
api_name="/predict"
|
| 104 |
+
)
|
| 105 |
|
| 106 |
# Hospedar a imagem e obter a URL
|
| 107 |
+
hosted_url = host_image(endpoint, result_path)
|
| 108 |
|
| 109 |
if hosted_url:
|
| 110 |
return jsonify({"result_url": hosted_url})
|