Spaces:
Sleeping
Sleeping
Avinyaa
commited on
Commit
Β·
703fff1
1
Parent(s):
1b567fa
- Dockerfile +21 -10
- app_config.py +18 -2
- startup.py +18 -9
Dockerfile
CHANGED
@@ -1,26 +1,37 @@
|
|
1 |
FROM python:3.11
|
2 |
|
3 |
-
|
|
|
4 |
|
5 |
-
#
|
6 |
-
ENV NUMBA_DISABLE_JIT=1
|
7 |
-
|
8 |
-
# Install git, git-lfs, and espeak-ng for Kokoro TTS
|
9 |
RUN apt-get update && apt-get install -y git git-lfs espeak-ng && rm -rf /var/lib/apt/lists/*
|
10 |
|
11 |
# Initialize git lfs
|
12 |
RUN git lfs install
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
# Expose the port
|
22 |
EXPOSE 7860
|
23 |
|
24 |
# Default command - use startup.py for debugging if needed
|
25 |
-
# CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
26 |
CMD ["python", "startup.py"]
|
|
|
1 |
FROM python:3.11
|
2 |
|
3 |
+
# Set up a new user named "user" with user ID 1000
|
4 |
+
RUN useradd -m -u 1000 user
|
5 |
|
6 |
+
# Install system dependencies as root
|
|
|
|
|
|
|
7 |
RUN apt-get update && apt-get install -y git git-lfs espeak-ng && rm -rf /var/lib/apt/lists/*
|
8 |
|
9 |
# Initialize git lfs
|
10 |
RUN git lfs install
|
11 |
|
12 |
+
# Switch to the "user" user
|
13 |
+
USER user
|
14 |
+
|
15 |
+
# Set home to the user's home directory
|
16 |
+
ENV HOME=/home/user \
|
17 |
+
PATH=/home/user/.local/bin:$PATH \
|
18 |
+
NUMBA_DISABLE_JIT=1
|
19 |
+
|
20 |
+
# Set the working directory to the user's home directory
|
21 |
+
WORKDIR $HOME/app
|
22 |
+
|
23 |
+
# Try and run pip command after setting the user with `USER user` to avoid permission issues with Python
|
24 |
+
RUN pip install --no-cache-dir --upgrade pip
|
25 |
|
26 |
+
# Copy requirements first and install dependencies
|
27 |
+
COPY --chown=user requirements.txt .
|
28 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
29 |
|
30 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
31 |
+
COPY --chown=user . $HOME/app
|
32 |
|
33 |
# Expose the port
|
34 |
EXPOSE 7860
|
35 |
|
36 |
# Default command - use startup.py for debugging if needed
|
|
|
37 |
CMD ["python", "startup.py"]
|
app_config.py
CHANGED
@@ -12,9 +12,16 @@ logger = logging.getLogger(__name__)
|
|
12 |
|
13 |
def setup_hf_cache():
|
14 |
"""Setup cache environment variables for Hugging Face Spaces"""
|
15 |
-
#
|
16 |
-
|
|
|
|
|
17 |
cache_settings = {
|
|
|
|
|
|
|
|
|
|
|
18 |
'NUMBA_DISABLE_JIT': '1',
|
19 |
'HF_HUB_DISABLE_TELEMETRY': '1'
|
20 |
}
|
@@ -24,6 +31,15 @@ def setup_hf_cache():
|
|
24 |
os.environ[key] = value
|
25 |
logger.info(f"Set {key} to {value}")
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
logger.info("Cache environment setup completed")
|
28 |
|
29 |
def get_temp_dir():
|
|
|
12 |
|
13 |
def setup_hf_cache():
|
14 |
"""Setup cache environment variables for Hugging Face Spaces"""
|
15 |
+
# Use user's home directory for cache
|
16 |
+
home_dir = os.path.expanduser("~")
|
17 |
+
cache_dir = os.path.join(home_dir, ".cache")
|
18 |
+
|
19 |
cache_settings = {
|
20 |
+
'HF_HOME': cache_dir,
|
21 |
+
'TRANSFORMERS_CACHE': cache_dir,
|
22 |
+
'HF_HUB_CACHE': cache_dir,
|
23 |
+
'TORCH_HOME': cache_dir,
|
24 |
+
'NUMBA_CACHE_DIR': os.path.join(cache_dir, 'numba'),
|
25 |
'NUMBA_DISABLE_JIT': '1',
|
26 |
'HF_HUB_DISABLE_TELEMETRY': '1'
|
27 |
}
|
|
|
31 |
os.environ[key] = value
|
32 |
logger.info(f"Set {key} to {value}")
|
33 |
|
34 |
+
# Create cache directories
|
35 |
+
cache_dirs = [cache_dir, os.path.join(cache_dir, 'numba')]
|
36 |
+
for cache_path in cache_dirs:
|
37 |
+
try:
|
38 |
+
os.makedirs(cache_path, exist_ok=True)
|
39 |
+
logger.info(f"Created cache directory: {cache_path}")
|
40 |
+
except Exception as e:
|
41 |
+
logger.warning(f"Could not create {cache_path}: {e}")
|
42 |
+
|
43 |
logger.info("Cache environment setup completed")
|
44 |
|
45 |
def get_temp_dir():
|
startup.py
CHANGED
@@ -26,6 +26,11 @@ def check_environment():
|
|
26 |
# Check Python version
|
27 |
logger.info(f"Python version: {sys.version}")
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
# Check available disk space
|
30 |
try:
|
31 |
result = subprocess.run(['df', '-h', '/tmp'], capture_output=True, text=True)
|
@@ -33,15 +38,17 @@ def check_environment():
|
|
33 |
except Exception as e:
|
34 |
logger.warning(f"Could not check disk space: {e}")
|
35 |
|
36 |
-
# Check write permissions for
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
45 |
|
46 |
def check_dependencies():
|
47 |
"""Check if required packages are installed"""
|
@@ -89,6 +96,8 @@ def test_kokoro():
|
|
89 |
|
90 |
except Exception as e:
|
91 |
logger.error(f"β Kokoro TTS test failed: {e}")
|
|
|
|
|
92 |
return False
|
93 |
|
94 |
def main():
|
|
|
26 |
# Check Python version
|
27 |
logger.info(f"Python version: {sys.version}")
|
28 |
|
29 |
+
# Check current user and home directory
|
30 |
+
logger.info(f"Current user: {os.getenv('USER', 'unknown')}")
|
31 |
+
logger.info(f"Home directory: {os.path.expanduser('~')}")
|
32 |
+
logger.info(f"Current working directory: {os.getcwd()}")
|
33 |
+
|
34 |
# Check available disk space
|
35 |
try:
|
36 |
result = subprocess.run(['df', '-h', '/tmp'], capture_output=True, text=True)
|
|
|
38 |
except Exception as e:
|
39 |
logger.warning(f"Could not check disk space: {e}")
|
40 |
|
41 |
+
# Check write permissions for important directories
|
42 |
+
test_dirs = ['/tmp', os.path.expanduser('~'), os.getcwd()]
|
43 |
+
for test_dir in test_dirs:
|
44 |
+
try:
|
45 |
+
test_file = os.path.join(test_dir, 'test_write.tmp')
|
46 |
+
with open(test_file, 'w') as f:
|
47 |
+
f.write('test')
|
48 |
+
os.remove(test_file)
|
49 |
+
logger.info(f"β
Write permission OK: {test_dir}")
|
50 |
+
except Exception as e:
|
51 |
+
logger.warning(f"β Write permission failed: {test_dir} - {e}")
|
52 |
|
53 |
def check_dependencies():
|
54 |
"""Check if required packages are installed"""
|
|
|
96 |
|
97 |
except Exception as e:
|
98 |
logger.error(f"β Kokoro TTS test failed: {e}")
|
99 |
+
import traceback
|
100 |
+
logger.error(f"Full traceback: {traceback.format_exc()}")
|
101 |
return False
|
102 |
|
103 |
def main():
|