Download issues!

Hello,

I’m trying to deploy a model using streamlit and I am having some troubles downloading my result. I’m using the download button from streamlit (st.download_button - Streamlit Docs), but every time I get the same error: “404 Sorry, we can’t find the page you are looking for”. Is there anyone that has faced the same issue with streamlit that can give me some advice? Or is there another way to download something on hugging face?

Thank you.

I currently have the same issue and could not resolve it.

I created my own link to download files from huggingface since the streamlit button is not working. Have a look over at this space, which also shows the problem with the link: Streamlit Download Experiment - a Hugging Face Space by cansik

But this only works for file sizes that do not exceed the url-charachter limit!

Btw. even downgrading does not work. I tried to stick to an old version of streamlit (like sdk_version: 1.21.0) and adding the altair==4.1.0 requirement (as mentioned here).

cc @whitphx currently maintaining Streamlit Spaces SDK

Thank you so much for the report!
Will investigate it with the infra team. Let us take a bit more.

@cansik Although we haven’t found the root cause yet, let me suggest one possible workaround:
I found that your Space is now configured to use Streamlit 1.12.2, not 1.21.0, and it may be solved by upgrading the Streamlit version to 1.21.0 for example, as I experimented in this Space which I duplicated yours.

@whitphx Yes I am aware of that, it was a test to see if it works with an older version, but the problem is that it does only work for smaller files, not large files (like 10mb). If you want I can create an example that shows the exact problem.

Ah, OK, you mentioned the problem of st.download_button() which occurs particularly with large files.
I encountered a different bug of the older version and misunderstood it.
Will take a look into it again.

I think found the problem: if the space is private, downloads do not work leading to 404 error, if the space is public it seems to work.

@cansik Thank you, that’s an important info! Can you share the code?


I was also trying to reproduce the error in my private Space, but couldn’t…
Can you try the code below when you have time, to check if the error occurs in your env or to specify the problem? Thank you.

README.md

---
title: Streamlit Private Download Experiment
emoji: 🌖
colorFrom: red
colorTo: red
sdk: streamlit
sdk_version: 1.21.0
app_file: app.py
pinned: false
license: mit
---

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

app.py

import random
import string
import streamlit as st

text_contents = '''This is some text'''
st.download_button('Download a small text file', text_contents)


@st.cache_data
def create_large_data():
    data = ''.join(random.choices(string.ascii_uppercase, k=1024 * 1024 * 10))
    data = bytes(data, "utf-8")
    return data

large_data = create_large_data()
st.download_button('Download a large file', large_data)

CleanShot 2023-07-01 at 00.32.49

I just noticed that I am using the Brave browser which disables cross-site-cookies for security reasons. Could it be that the cookie for huggingface.co is not valid for cansik-streamlit-download-experiment.hf.space which seems like the address for the media download?

By disabling the cookie blocker it works now also on private repositories! Thank you for helping me with this issue. If this is really the issue, maybe there should be an access denied error shown instead of the 404. This would it make more clear (and maybe a message to disable the cookie / ad blocker). Or changing the download url to the original url instead of a subdomain.

@cansik Thank you very much, that’s so helpful investigation!
I also could confirm the error with Brave.
I will let our infra team know this topic and your suggestion, and make some discussions!

1 Like

My space was also private, but I have decided to move my model for a local server and after that I didn’t try it here again.

However, thank you, everyone.