Spaces:
Running on Zero
Running on Zero
Spread the gradio_client token keyword rather than shadowing the client factory
Browse files
app.py
CHANGED
|
@@ -11,6 +11,9 @@ from pyharp import *
|
|
| 11 |
from gradio_client import Client, handle_file
|
| 12 |
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
_BACKEND_SPACE = "facebook/MelodyFlow"
|
| 15 |
_BACKEND_API_NAME = "/predict"
|
| 16 |
_BACKEND_TOKEN_ENV = "HF_TOKEN"
|
|
@@ -29,7 +32,7 @@ def _backend_client():
|
|
| 29 |
global _client
|
| 30 |
if _client is None:
|
| 31 |
_token = os.environ.get(_BACKEND_TOKEN_ENV) or None
|
| 32 |
-
_client =
|
| 33 |
return _client
|
| 34 |
|
| 35 |
|
|
@@ -43,7 +46,7 @@ def _reset_client():
|
|
| 43 |
def _make_conn(tok):
|
| 44 |
tok = (tok or '').strip()
|
| 45 |
if tok:
|
| 46 |
-
return
|
| 47 |
return _backend_client()
|
| 48 |
|
| 49 |
|
|
|
|
| 11 |
from gradio_client import Client, handle_file
|
| 12 |
|
| 13 |
|
| 14 |
+
_TOKEN_ARG = ("token" if "token" in inspect.signature(Client.__init__).parameters
|
| 15 |
+
else "hf_token")
|
| 16 |
+
|
| 17 |
_BACKEND_SPACE = "facebook/MelodyFlow"
|
| 18 |
_BACKEND_API_NAME = "/predict"
|
| 19 |
_BACKEND_TOKEN_ENV = "HF_TOKEN"
|
|
|
|
| 32 |
global _client
|
| 33 |
if _client is None:
|
| 34 |
_token = os.environ.get(_BACKEND_TOKEN_ENV) or None
|
| 35 |
+
_client = Client(_BACKEND_SPACE, **{_TOKEN_ARG: _token})
|
| 36 |
return _client
|
| 37 |
|
| 38 |
|
|
|
|
| 46 |
def _make_conn(tok):
|
| 47 |
tok = (tok or '').strip()
|
| 48 |
if tok:
|
| 49 |
+
return Client(_BACKEND_SPACE, **{_TOKEN_ARG: tok})
|
| 50 |
return _backend_client()
|
| 51 |
|
| 52 |
|