One python script for a automated inpaint model inference. It will take 2 arguments: 1) for the image path and 2) for the prompt and the function will do as follows:

1) It will first create a mask for the image by running a function called create_mask with image_path as input. The create_mask function will return the path of the newly, created mask. 

2)  Next we will need to make a composite image, this will be done by overlaying the mask over the original image.
3) Afterwards, the function will upload the files to the server via this post request endpoint https://ozzygt-diffusers-fast-inpaint.hf.space/upload


With the following headers

accept:
*/*
accept-encoding:
gzip, deflate, br, zstd
accept-language:
en-US,en;q=0.6
content-length:
421366
content-type:
multipart/form-data; boundary=----WebKitFormBoundaryWnVNm2A2xuNieOdn
dnt:
1
origin:
https://ozzygt-diffusers-fast-inpaint.hf.space
priority:
u=1, i
referer:
https://ozzygt-diffusers-fast-inpaint.hf.space/?__theme=light
sec-ch-ua:
"Chromium";v="130", "Brave";v="130", "Not?A_Brand";v="99"
sec-ch-ua-mobile:
?0
sec-ch-ua-platform:
"Windows"
sec-fetch-dest:
empty
sec-fetch-mode:
cors
sec-fetch-site:
same-origin
sec-gpc:
1
user-agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36

And the data attached should look like this:

file: (binary)

The endpoint will return a json list like ['path'] with one item which will be the path locally on the server.

4) With the paths from the server retrieved, make a new post request to the endpoint https://ozzygt-diffusers-fast-inpaint.hf.space/queue/join?__theme=light

with headers like this:

accept:
*/*
accept-encoding:
gzip, deflate, br, zstd
accept-language:
en-US,en;q=0.6
content-length:
1199
content-type:
application/json
dnt:
1
origin:
https://ozzygt-diffusers-fast-inpaint.hf.space
priority:
u=1, i
referer:
https://ozzygt-diffusers-fast-inpaint.hf.space/?__theme=light
sec-ch-ua:
"Chromium";v="130", "Brave";v="130", "Not?A_Brand";v="99"
sec-ch-ua-mobile:
?0
sec-ch-ua-platform:
"Windows"
sec-fetch-dest:
empty
sec-fetch-mode:
cors
sec-fetch-site:
same-origin
sec-gpc:
1
user-agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36

And data like this:

{
    "data": [
        "Placeholder prompt",
        {
            "background": {
                "path": "/tmp/gradio/7e2af5d1de520dec04b80ac27b2ba40521b2d64afc7c7c69d75572c9c216d8b2/background.png",
                "url": "https://ozzygt-diffusers-fast-inpaint.hf.space/file=/tmp/gradio/7e2af5d1de520dec04b80ac27b2ba40521b2d64afc7c7c69d75572c9c216d8b2/background.png",
                "orig_name": "background.png",
                "size": 421163,
                "mime_type": "",
                "meta": {
                    "_type": "gradio.FileData"
                }
            },
            "layers": [
                {
                    "path": "/tmp/gradio/e6a33139433217d004aed620c5cc1c3c9b89d63ad739e81a76b545ddda0c3117/layer_0.png",
                    "url": "https://ozzygt-diffusers-fast-inpaint.hf.space/file=/tmp/gradio/e6a33139433217d004aed620c5cc1c3c9b89d63ad739e81a76b545ddda0c3117/layer_0.png",
                    "orig_name": "layer_0.png",
                    "size": 12957,
                    "mime_type": "",
                    "meta": {
                        "_type": "gradio.FileData"
                    }
                }
            ],
            "composite": {
                "path": "/tmp/gradio/d1d8fcc156eb76fcedf40749f46a9f337449d63cedec40987e612e1333b8ab6f/composite.png",
                "url": "https://ozzygt-diffusers-fast-inpaint.hf.space/file=/tmp/gradio/d1d8fcc156eb76fcedf40749f46a9f337449d63cedec40987e612e1333b8ab6f/composite.png",
                "orig_name": "composite.png",
                "size": 213377,
                "mime_type": "",
                "meta": {
                    "_type": "gradio.FileData"
                }
            }
        },
        "RealVisXL V5.0 Lightning",
        true
    ],
    "event_data": null,
    "fn_index": 3,
    "trigger_id": 10,
    "session_hash": "unznewbak3"
}


Generate a random string for the session hash.


5) Using the same session hash generated for that post request, get request this endpoint and stream it. 
https://ozzygt-diffusers-fast-inpaint.hf.space/queue/data?session_hash=ur_sessionhash123

with the following headers:

accept:
text/event-stream
accept-encoding:
gzip, deflate, br, zstd
accept-language:
en-US,en;q=0.6
content-type:
application/json
dnt:
1
priority:
u=1, i
referer:
https://ozzygt-diffusers-fast-inpaint.hf.space/?__theme=light
sec-ch-ua:
"Chromium";v="130", "Brave";v="130", "Not?A_Brand";v="99"
sec-ch-ua-mobile:
?0
sec-ch-ua-platform:
"Windows"
sec-fetch-dest:
empty
sec-fetch-mode:
cors
sec-fetch-site:
same-origin
sec-gpc:
1
user-agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36


And then retrieve the second to last message which should look like this:

{"msg":"process_completed","event_id":"48fceb6a94b1426b9842622fecc63da1","output":{"data":[[{"path":"/tmp/gradio/2d5d4ded67e54140fb4d65e6b467ab3091d29bbdda0f2f5de594dd2b15f63457/image.webp","url":"https://ozzygt-diffusers-fast-inpaint.hf.space/file=/tmp/gradio/2d5d4ded67e54140fb4d65e6b467ab3091d29bbdda0f2f5de594dd2b15f63457/image.webp","size":null,"orig_name":null,"mime_type":null,"is_stream":false,"meta":{"_type":"gradio.FileData"}},{"path":"/tmp/gradio/6a0b77ffd6b24da0b8430b4581582bdda119550534908cdb52b72de31a51b2ff/image.webp","url":"https://ozzygt-diffusers-fast-inpaint.hf.space/file=/tmp/gradio/6a0b77ffd6b24da0b8430b4581582bdda119550534908cdb52b72de31a51b2ff/image.webp","size":null,"orig_name":null,"mime_type":null,"is_stream":false,"meta":{"_type":"gradio.FileData"}}]],"is_generating":false,"duration":0.0016963481903076172,"average_duration":0.519971223674512,"render_config":null,"changed_state_ids":[]},"success":true}


And print the second files url