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

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -13
main.py CHANGED
@@ -6,10 +6,10 @@ from huggingface_hub import create_repo, upload_file
6
 
7
  app = Flask(__name__)
8
 
9
- def host_image(image_path):
10
- api_url = "https://wosocial.bubbleapps.io/version-test/api/1.1/wf/save"
11
- files = {'file': open(image_path, 'rb')}
12
- response = requests.post(api_url, files=files)
13
  if response.status_code == 200:
14
  return response.json()["response"]["result"]
15
  else:
@@ -92,17 +92,12 @@ def faceswapper():
92
  endpoint = request.args.get('endpoint', default='https://pierroromeu-faceswapper.hf.space/--replicas/u42x7/')
93
  user_photo = request.args.get('user_photo', default='')
94
  result_photo = request.args.get('result_photo', default='')
95
-
96
- # Chamar a API Gradio
97
- client = Client(endpoint, upload_files=True)
98
- result_path = client.predict(
99
- user_photo,
100
- result_photo,
101
- api_name="/predict"
102
- )
103
 
104
  # Hospedar a imagem e obter a URL
105
- hosted_url = host_image(result_path)
106
 
107
  if hosted_url:
108
  return jsonify({"result_url": hosted_url})
 
6
 
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:
 
92
  endpoint = request.args.get('endpoint', default='https://pierroromeu-faceswapper.hf.space/--replicas/u42x7/')
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})