hugofloresgarcia commited on
Commit
2760947
·
1 Parent(s): 7cfd544

Add HF_TOKEN authentication support for model access

Browse files
Files changed (2) hide show
  1. README.md +11 -0
  2. app.py +13 -0
README.md CHANGED
@@ -31,6 +31,17 @@ Generate up to 4 audio variations from a single text prompt using Stability AI's
31
  - **Variable Duration**: Control audio length (1-11 seconds)
32
  - **Fast Generation**: Uses optimized pingpong sampler with 8 steps
33
 
 
 
 
 
 
 
 
 
 
 
 
34
  ## Usage
35
 
36
  1. Enter a text prompt describing the audio you want to generate
 
31
  - **Variable Duration**: Control audio length (1-11 seconds)
32
  - **Fast Generation**: Uses optimized pingpong sampler with 8 steps
33
 
34
+ ## Setup
35
+
36
+ This model requires accepting the license agreement on Hugging Face. To use this Space:
37
+
38
+ 1. **Accept the model license**: Visit [stabilityai/stable-audio-open-small](https://huggingface.co/stabilityai/stable-audio-open-small) and accept the license agreement
39
+ 2. **Create an access token**: Go to [Settings > Access Tokens](https://huggingface.co/settings/tokens) and create a token with "read" permissions
40
+ 3. **Add token to Space**: In your Space settings, go to "Variables and secrets" and add a new secret:
41
+ - Name: `HF_TOKEN`
42
+ - Value: Your access token
43
+ - Make sure it's marked as private
44
+
45
  ## Usage
46
 
47
  1. Enter a text prompt describing the audio you want to generate
app.py CHANGED
@@ -1,8 +1,10 @@
1
  import torch
2
  import torchaudio
3
  import gradio as gr
 
4
  from stable_audio_tools import get_pretrained_model
5
  from stable_audio_tools.inference.generation import generate_diffusion_cond
 
6
 
7
  # Global model variables
8
  model = None
@@ -16,6 +18,15 @@ def load_model():
16
  device = "cuda" if torch.cuda.is_available() else "cpu"
17
  print(f"Loading model on device: {device}")
18
 
 
 
 
 
 
 
 
 
 
19
  # Download and load the pretrained model
20
  model, model_config = get_pretrained_model("stabilityai/stable-audio-open-small")
21
  sample_rate = model_config["sample_rate"]
@@ -99,6 +110,8 @@ with gr.Blocks(title="Stable Audio Open Small - 4 Variations") as demo:
99
 
100
  **Model**: [stabilityai/stable-audio-open-small](https://huggingface.co/stabilityai/stable-audio-open-small)
101
 
 
 
102
  Enter a text description and click Generate to create 4 different audio variations.
103
  """)
104
 
 
1
  import torch
2
  import torchaudio
3
  import gradio as gr
4
+ import os
5
  from stable_audio_tools import get_pretrained_model
6
  from stable_audio_tools.inference.generation import generate_diffusion_cond
7
+ from huggingface_hub import login
8
 
9
  # Global model variables
10
  model = None
 
18
  device = "cuda" if torch.cuda.is_available() else "cpu"
19
  print(f"Loading model on device: {device}")
20
 
21
+ # Check for HF_TOKEN environment variable (set in Space settings)
22
+ hf_token = os.getenv("HF_TOKEN")
23
+ if hf_token:
24
+ print("Using HF_TOKEN for authentication")
25
+ login(token=hf_token)
26
+ else:
27
+ print("Warning: HF_TOKEN not found. Model access may fail if authentication is required.")
28
+ print("Please set HF_TOKEN as a secret in your Space settings.")
29
+
30
  # Download and load the pretrained model
31
  model, model_config = get_pretrained_model("stabilityai/stable-audio-open-small")
32
  sample_rate = model_config["sample_rate"]
 
110
 
111
  **Model**: [stabilityai/stable-audio-open-small](https://huggingface.co/stabilityai/stable-audio-open-small)
112
 
113
+ **Note**: This model requires accepting the license agreement. Make sure to set `HF_TOKEN` as a secret in your Space settings.
114
+
115
  Enter a text description and click Generate to create 4 different audio variations.
116
  """)
117