Text-to-Speech
English

Question about accessing private Space via API

#103
by bezprzesadyco - opened

I have a private Space with Kokoro TTS model running with Gradio interface. The web UI works fine, but I'm having issues with API access.
What I'm trying to do:

Access my private Space via API to:

Send text
Get generated audio back

Use it with external tools (like n8n)

What I've tried:
pythonCopyfrom gradio_client import Client

client = Client(
"my-username/Kokoro-TTS",
hf_token="my_token"
)

result = client.predict(
text="Test text",
voice="af_heart",
speed=1,
use_gpu=False,
api_name="/generate_all"
)
Error I'm getting:
CopyValueError: Could not fetch api info for https://my-username-kokoro-tts.hf.space
Questions:

Is it possible to use API with private Spaces?
If yes, what's the correct way to set it up?
Are there any specific settings needed in the Space configuration?

Any help would be appreciated!

Yes. This is more of a general Gradio space question.

But you need to set it up so that the my_token has read access to the private space.
https://huggingface.co/settings/tokens/new?tokenType=fineGrained

And you need api_enabled api_open=true for Gradio.

Thanks for your reply. We've tried several approaches:

  1. Set up API access with:
API_OPEN = True
API_NAME = "/generate_all"
  1. Configured launch parameters:
app.queue().launch(
    server_name="0.0.0.0",
    server_port=7860,
    share=True,
    api_open=True,
    show_api=True
)
  1. Used gradio client with token:
client = Client(
    "bezprzesadyco/Kokoro-TTS",
    hf_token="my_token"
)

But we keep getting either:

  • TypeError: Blocks.launch() got an unexpected keyword argument 'api_open'
  • or ValueError: Could not fetch api info for https://bezprzesadyco-kokoro-tts.hf.space

We already have a token with read access. Any idea what might be wrong with our setup?

api_open is part of .queue() arguments, not .launch().

another day another try
edited:
app.py

if name == 'main':
app.queue(api_open=API_OPEN).launch(show_api=API_OPEN, ssr_mode=True)

but when i try call api i got:

SvelteKitError: POST method not allowed. No actions exist for this page
at handle_action_json_request (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/server/index.js:875:30)
at render_page (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/server/index.js:2526:12)
at async resolve2 (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/server/index.js:3654:24)
at async respond (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/server/index.js:3545:22)
at async Array.ssr (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/handler.js:1261:3) {
status: 405,
text: 'Method Not Allowed'
}

Sign up or log in to comment