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
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
{"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
1 Like
The image is saved normally, but is there something wrong with the settings?
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")
1 Like
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.
1 Like