Spaces:
Running
on
T4
Running
on
T4
| import requests | |
| #HEALTH CHECK | |
| response = requests.get("https://logicgoinfotechspaces-faceswap.hf.space/health") | |
| print(response.status_code) # Should be 200 | |
| print(response.json()) # Should print: {'status': 'healthy'} | |
| #----------------------------------------------------------------------------------------------------# | |
| #UPLOAD SOURCE IMAGE | |
| with open("./source.jpeg", "rb") as f: | |
| files = {"image": ("./source.jpeg", f, "image/jpeg")} | |
| response = requests.post("https://logicgoinfotechspaces-faceswap.hf.space/source", files=files) | |
| print(response.status_code) # Should be 200 | |
| print(response.json()) # Should print: {'source_id': '<id>'} | |
| source_id = response.json().get("source_id") | |
| #----------------------------------------------------------------------------------------------------# | |
| #UPLOAD TARGET IMAGE | |
| with open("./target.jpeg", "rb") as f: | |
| files = {"image": ("./target.jpeg", f, "image/jpeg")} | |
| response = requests.post("https://logicgoinfotechspaces-faceswap.hf.space/target", files=files) | |
| print(response.status_code) # Should be 200 | |
| print(response.json()) # Should print: {'target_id': '<id>'} | |
| target_id = response.json().get("target_id") | |
| #----------------------------------------------------------------------------------------------------# | |
| #SWAP IMAGES | |
| source_id = "68bff17eb3b2e06c24cafa22" # Replace with actual ID | |
| target_id = "68bff1a1b3b2e06c24cafa23" # Replace with actual ID | |
| payload = {"source_id": source_id, "target_id": target_id} | |
| response = requests.post("https://logicgoinfotechspaces-faceswap.hf.space/faceswap", json=payload) | |
| print(response.status_code) # Should be 200 | |
| print(response.json()) # Should print: {'result_id': '<id>'} | |
| result_id = response.json().get("result_id") | |
| #----------------------------------------------------------------------------------------------------# | |
| #DOWNLOAD IMAGES | |
| result_id = "68bff4800e80c0bb228b5962" # Replace with actual ID | |
| response = requests.get(f"https://logicgoinfotechspaces-faceswap.hf.space/download/{result_id}") | |
| print(response.status_code) # Should be 200 | |
| if response.status_code == 200: | |
| with open("result.png", "wb") as f: | |
| f.write(response.content) | |
| print("Image downloaded as result.png") | |
| else: | |
| print(response.json()) # Print error details | |
| #----------------------------------------------------------------------------------------------------# |