import gradio as gr def GetFile(): return "https://huggingface.co/spaces/rrg92/GradioApiBug/raw/main/SampleFile.txt" with gr.Blocks() as demo: gr.Markdown(""" This space demonstrates an issue with the Gradio API related to file donwloads. You can use any preferred HTTP client to reproduce the issue. Refer to the sample code below. **Problem**: The file URL returned by the Gradio API is incorrect. this a sample curl code: ```bash space="https://rrg92-gradioapibug.hf.space"; curl -X POST "$space/call/GetFile" -s -H "Content-Type: application/json" -d '{"data":[]}' | awk -F'"' '{print $4}' | { read event; curl -s "$space/call/GetFile/$event" | grep -oEi '"url": ".*?"' | awk -F'"' '{print $4}' ; } ``` this is same version, but can run in Powershell ```posh $space = "https://rrg92-gradioapibug.hf.space"; iwr -met POST -Uri "$space/call/GetFile" -Body '{"data":[]}' -ContentType "application/json" | ConvertFrom-Json | %{ $_.event_id } | %{ iwr -uri "$space/call/GetFile/$_" } | %{$null=$_.content -match "data: (.+)"; $matches[1] } | ConvertFrom-Json | %{ $_.url} ``` The sample code is supposed to output a URL path to a file generated by the Gradio API. However, if you try to access the link, it returns a "not found" error. The issue arises because the 'url' field returned by the API is incorrect. It should follow the format: `HOST/FILE=PATH`, but it returns a different path. In my tests, I couldn't determine the exact path, but for example, it returns something like `HOST/c/file=PATH`. In other cases, I've seen it return paths such as `HOST/call/ApiName/file=PATH`. """) btn = gr.Button("Click that button to start!") fileResult = gr.File() btn.click( GetFile, None, [fileResult] ) if __name__ == "__main__": demo.launch(show_api=True)