Accessing files generated via API

#1
by slapula - opened

This may be a dumb question but how do you access the files generated by the API endpoint?

❯ curl -X POST https://jhlfrfufyfn-bel-tts.hf.space/run/predict \
   -H 'Content-Type: application/json' \
   -d '{"data":["Выбачайце!"]}'
{"data":[{"name":"/tmp/tmpg3ph1k84/tmp4zmkjpvk914pp2h4.wav","data":null,"is_file":true}],"is_generating":false,"duration":2.674603223800659,"average_duration":12.76511879854424}

❯ wget https://jhlfrfufyfn-bel-tts.hf.space/tmp/tmpg3ph1k84/tmp4zmkjpvk914pp2h4.wav
--2023-09-01 09:45:31--  https://jhlfrfufyfn-bel-tts.hf.space/tmp/tmpg3ph1k84/tmp4zmkjpvk914pp2h4.wav
Resolving jhlfrfufyfn-bel-tts.hf.space (jhlfrfufyfn-bel-tts.hf.space)... 3.95.36.67, 44.207.251.54, 3.220.95.64
Connecting to jhlfrfufyfn-bel-tts.hf.space (jhlfrfufyfn-bel-tts.hf.space)|3.95.36.67|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2023-09-01 09:45:31 ERROR 404: Not Found.

❯ wget https://jhlfrfufyfn-bel-tts.hf.space/run/predict/tmp/tmpg3ph1k84/tmp4zmkjpvk914pp2h4.wav
--2023-09-01 09:45:54--  https://jhlfrfufyfn-bel-tts.hf.space/run/predict/tmp/tmpg3ph1k84/tmp4zmkjpvk914pp2h4.wav
Resolving jhlfrfufyfn-bel-tts.hf.space (jhlfrfufyfn-bel-tts.hf.space)... 3.95.36.67, 44.207.251.54, 3.220.95.64
Connecting to jhlfrfufyfn-bel-tts.hf.space (jhlfrfufyfn-bel-tts.hf.space)|3.95.36.67|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2023-09-01 09:45:54 ERROR 404: Not Found.

Hi! Sorry it took so much time to answer.

I am not really sure that you can access temp files by the url like that.

You can see how I access the files in the file app.py in space's files, I am using tempfile package there (as far as I remember:)

No worries! I actually cloned your project and figured it out by running it from my account. I ended up using this to generate audio for ~5000 Anki cards that I created based on the lexicon used for https://languagedrops.com/ (which doesn't currently support Belarusian). I don't have it shared publically on AnkiWeb just yet but I can post a link to it here when it's ready :-)

That's really cool! Looking forward to seeing that project

Thanks! That looks like something that could improve my Belarusian.

By the way, how did you manage to pull temp fules from huggingface? I think I know people a few people who could use it.

The trick is the URL. You need use something like this: "https://jhlfrfufyfn-bel-tts.hf.space/file=". The path you get from the API response is what you append to that URL. So if I used the above error I posted as an example, a valid download link would look like this: "https://jhlfrfufyfn-bel-tts.hf.space/file=/tmp/tmpg3ph1k84/tmp4zmkjpvk914pp2h4.wav". They are temp files so they only stick around for a short time (which is probably why huggingface offers persistent storage). With that in mind, you'll want to download the file immediately after generating them so you don't end up trying to hit expired links.

Sign up or log in to comment