# Issues with gradio client

**URL:** <https://discuss.huggingface.co/t/issues-with-gradio-client/134215>\
**Category:** Spaces\
**Created:** [January 4, 2025, 9:52am UTC](https://discuss.huggingface.co/t/issues-with-gradio-client/134215 "2025-01-04T09:52:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kampaa201](https://avatars.discourse-cdn.com/v4/letter/k/7bcc69/32.png) [@kampaa201](https://discuss.huggingface.co/u/kampaa201)\
**Post date:** [January 4, 2025, 9:52am UTC](https://discuss.huggingface.co/t/issues-with-gradio-client/134215/1 "2025-01-04T09:52:42Z")

</div>

```auto
from gradio_client import Client

# Connect to the Gradio client
client = Client("black-forest-labs/FLUX.1-schnell")

# Call the inference endpoint
result = client.predict(
    "/infer", # Endpoint
    { 
        "prompt": "Hello!!", # Input parameters
        "seed": 0,
        "randomize_seed": True,
        "width": 256,
        "height": 256,
        "num_inference_steps": 1
    }
)

result

```

this is the code and the output of code is

```auto
Loaded as API: https://black-forest-labs-flux-1-schnell.hf.space ✔
('/tmp/gradio/489613c1bc4fe4fcf1b0e5a1d10b5977449d157f9eae4ccd9b8117765eabca12/image.webp',
 653764749)

```

after that i tried to get the actual generated image and it’s not showing

the full url look like

[https://black-forest-labs-flux-1-schnell.hf.space/file=/tmp/gradio/489613c1bc4fe4fcf1b0e5a1d10b5977449d157f9eae4ccd9b8117765eabca12/image.webp](https://black-forest-labs-flux-1-schnell.hf.space/file=/tmp/gradio/489613c1bc4fe4fcf1b0e5a1d10b5977449d157f9eae4ccd9b8117765eabca12/image.webp)

```auto
{"detail":"File not found: /tmp/gradio/489613c1bc4fe4fcf1b0e5a1d10b5977449d157f9eae4ccd9b8117765eabca12/image.webp."}

```

tell me what to do , this happen only while using through api ,

and if i use it in space , there’s no issue.

please tell me what to do

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [January 6, 2025, 3:30am UTC](https://discuss.huggingface.co/t/issues-with-gradio-client/134215/2 "2025-01-06T03:30:09Z")

</div>

The image is saved normally, but is there something wrong with the settings?

```py
from gradio_client import Client
from PIL import Image

# Connect to the Gradio client
client = Client("black-forest-labs/FLUX.1-schnell")

# Call the inference endpoint
result = client.predict(
    "/infer", # Endpoint
    { 
        "prompt": "Hello!!", # Input parameters
        "seed": 0,
        "randomize_seed": True,
        "width": 256,
        "height": 256,
        "num_inference_steps": 1
    }
)

imagepath, seed = result
image = Image.open(imagepath)
image.save("test1.webp")

```

---

<div class="post-metadata">

**Author:** ![Alanturner2](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/alanturner2/32/37542_2.png) [@Alanturner2](https://discuss.huggingface.co/u/Alanturner2)\
**Post date:** [January 6, 2025, 7:16am UTC](https://discuss.huggingface.co/t/issues-with-gradio-client/134215/3 "2025-01-06T07:16:31Z")

</div>

The issue you’re encountering stems from the fact that Gradio Spaces temporarily generate files in a `/tmp` directory on the server. These files may not persist after the request is processed, which can cause a “File not found” error when accessed via the API.

When using the API, the file path provided (e.g., `/tmp/gradio/...`) is typically not a public-facing URL but a server-side temporary location. It works fine in the Gradio Space interface because the file is served directly by the UI for a limited time.

````
 ```python
 import base64

 def inference(prompt, seed, randomize_seed, width, height, num_inference_steps):
     # Existing logic
     image_path = "/tmp/gradio/489613c1bc4fe4fcf1b0e5a1d10b5977449d157f9eae4ccd9b8117765eabca12/image.webp"
     with open(image_path, "rb") as image_file:
         image_data = base64.b64encode(image_file.read()).decode("utf-8")
     return {"image_data": image_data}

 iface = gr.Interface(inference, inputs=[...], outputs=["json"])
 iface.launch()
 ```

````

This way, the response will include the encoded image content, which can be decoded and saved locally.
