OnyxMunk commited on
Commit
fa03fad
·
1 Parent(s): 2a22076

Add Hugging Face authentication and update server port

Browse files

- Implemented environment variable loading with dotenv for Hugging Face token.
- Added Hugging Face authentication logic in app.py with error handling.
- Updated README with setup instructions for Hugging Face authentication.
- Changed server port from 7860 to 8080 in app.py.
- Added huggingface_hub and python-dotenv to requirements.txt.

Files changed (5) hide show
  1. Dockerfile +2 -0
  2. README.md +16 -0
  3. __pycache__/app.cpython-310.pyc +0 -0
  4. app.py +18 -1
  5. requirements.txt +2 -0
Dockerfile CHANGED
@@ -10,6 +10,8 @@ ENV PYTHONUNBUFFERED=1
10
  ENV GRADIO_SERVER_NAME=0.0.0.0
11
  ENV GRADIO_SERVER_PORT=7860
12
  ENV HF_HOME=/tmp/.cache/huggingface
 
 
13
 
14
  # Install system dependencies for audio processing and ML libraries
15
  RUN apt-get update && apt-get install -y \
 
10
  ENV GRADIO_SERVER_NAME=0.0.0.0
11
  ENV GRADIO_SERVER_PORT=7860
12
  ENV HF_HOME=/tmp/.cache/huggingface
13
+ # Optional: Set HF_TOKEN for Hugging Face authentication
14
+ # ENV HF_TOKEN=your_token_here
15
 
16
  # Install system dependencies for audio processing and ML libraries
17
  RUN apt-get update && apt-get install -y \
README.md CHANGED
@@ -21,6 +21,22 @@ An open-source web interface for generating high-quality audio from text prompts
21
  - 🎧 **Real-time Playback**: Listen to generated audio instantly
22
  - 📝 **Example Prompts**: Pre-built examples to get you started
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ## Usage
25
 
26
  1. Enter a text description of the audio you want to generate
 
21
  - 🎧 **Real-time Playback**: Listen to generated audio instantly
22
  - 📝 **Example Prompts**: Pre-built examples to get you started
23
 
24
+ ## Setup
25
+
26
+ ### Hugging Face Authentication (Recommended)
27
+
28
+ For the best experience and to avoid rate limits, set up Hugging Face authentication:
29
+
30
+ 1. Create a Hugging Face account at [huggingface.co](https://huggingface.co/join)
31
+ 2. Go to [Settings > Access Tokens](https://huggingface.co/settings/tokens) and create a new token
32
+ 3. Copy `env-example.txt` to `.env` and add your token:
33
+ ```
34
+ HF_TOKEN=hf_your_token_here
35
+ ```
36
+ 4. Install dependencies: `pip install -r requirements.txt`
37
+
38
+ **Note**: Without authentication, you may experience rate limits or reduced access to some models.
39
+
40
  ## Usage
41
 
42
  1. Enter a text description of the audio you want to generate
__pycache__/app.cpython-310.pyc CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
 
app.py CHANGED
@@ -3,6 +3,8 @@ import numpy as np
3
  import torch
4
  import os
5
  import warnings
 
 
6
 
7
  # Try to import Stable Audio pipeline
8
  try:
@@ -21,6 +23,21 @@ except ImportError:
21
  # Suppress warnings for cleaner output
22
  warnings.filterwarnings("ignore", category=UserWarning)
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # Model configuration
25
  MODEL_ID = "stabilityai/stable-audio-open-small"
26
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
@@ -417,4 +434,4 @@ if __name__ == "__main__":
417
  print(f"CUDA device: {torch.cuda.get_device_name(0)}")
418
 
419
  interface = create_audio_generation_interface()
420
- interface.launch(server_name="0.0.0.0", server_port=7860)
 
3
  import torch
4
  import os
5
  import warnings
6
+ from dotenv import load_dotenv
7
+ from huggingface_hub import login
8
 
9
  # Try to import Stable Audio pipeline
10
  try:
 
23
  # Suppress warnings for cleaner output
24
  warnings.filterwarnings("ignore", category=UserWarning)
25
 
26
+ # Load environment variables
27
+ load_dotenv()
28
+
29
+ # Set up Hugging Face authentication
30
+ hf_token = os.getenv("HF_TOKEN")
31
+ if hf_token:
32
+ try:
33
+ login(token=hf_token)
34
+ print("✅ Hugging Face authentication successful")
35
+ except Exception as e:
36
+ print(f"⚠️ Hugging Face authentication failed: {e}")
37
+ print(" Continuing without authentication...")
38
+ else:
39
+ print("ℹ️ No Hugging Face token found. Some models may have rate limits.")
40
+
41
  # Model configuration
42
  MODEL_ID = "stabilityai/stable-audio-open-small"
43
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
 
434
  print(f"CUDA device: {torch.cuda.get_device_name(0)}")
435
 
436
  interface = create_audio_generation_interface()
437
+ interface.launch(server_name="0.0.0.0", server_port=8080)
requirements.txt CHANGED
@@ -5,3 +5,5 @@ diffusers>=0.25.0
5
  transformers>=4.35.0
6
  accelerate>=0.25.0
7
  scipy>=1.7.0
 
 
 
5
  transformers>=4.35.0
6
  accelerate>=0.25.0
7
  scipy>=1.7.0
8
+ huggingface_hub>=0.17.0
9
+ python-dotenv>=1.0.0