craftgamesnetwork commited on
Commit
39ba7a3
·
verified ·
1 Parent(s): 8147977

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -6
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(image_url):
11
- api_url = "https://wosocial.bubbleapps.io/version-test/api/1.1/wf/save?file=" + image_url
12
- response = requests.get(api_url)
 
 
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
- # Formar a URL completa
97
- full_url = endpoint + "/file=" + result_photo
 
 
 
 
 
98
 
99
  # Hospedar a imagem e obter a URL
100
- hosted_url = host_image(full_url)
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})