File size: 1,501 Bytes
43c5517
 
 
 
 
 
79043a8
 
43c5517
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79043a8
 
 
 
 
 
 
 
 
 
 
 
 
e3d5df0
79043a8
 
 
 
 
 
 
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
import requests
import base64
from PIL import Image
import io

def call_inpaint_api(image_path, mask_path, prompt):
    # Update with your actual space URL
    url = "https://yaseengoldfinchpc-modeltest.hf.space/inpaint"
    
    files = {
        'image': open(image_path, 'rb'),
        'mask': open(mask_path, 'rb')
    }
    
    data = {
        'prompt': prompt
    }
    
    response = requests.post(url, files=files, data=data)
    
    if response.status_code == 200:
        # Decode base64 image
        img_data = base64.b64decode(response.json()['image'])
        img = Image.open(io.BytesIO(img_data))
        img.save('result.png')
        return 'result.png'
    else:
        print(f"Error: {response.text}")
        return None

def main():
    # First test health endpoint
    print("Testing health endpoint...")
    response = requests.get("https://yaseengoldfinchpc-modeltest.hf.space/health")
    print("Health Status:", response.json())
    
    # Test inpainting
    print("\nTesting inpainting...")
    # Replace these with your actual image paths
    image_path = r"C:\Users\M. Y\Downloads\t2.png"  # Replace with your image path
    mask_path = "generated_mask_1.png"   # Replace with your mask path
    prompt = "add some Chair tables and a fountain"
    
    result = call_inpaint_api(image_path, mask_path, prompt)
    if result:
        print(f"Success! Result saved as: {result}")

if __name__ == "__main__":
    main()