File size: 2,397 Bytes
0fd380e
c0b300b
 
0fd380e
 
 
 
c0b300b
0fd380e
c0b300b
0fd380e
 
 
 
 
 
 
c0b300b
0fd380e
c0b300b
0fd380e
 
 
 
 
 
 
c0b300b
0fd380e
 
 
c0b300b
 
 
 
 
 
0fd380e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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

#----------------------------------------------------------------------------------------------------#