Spaces:
Sleeping
Sleeping
ftshijt
commited on
Commit
·
73d9817
1
Parent(s):
a4807ff
remove fix for unusual issue
Browse files- Dockerfile +0 -4
- fix_nltk_permissions.py +0 -81
Dockerfile
CHANGED
@@ -38,10 +38,6 @@ RUN git clone https://github.com/wavlab-speech/versa.git && \
|
|
38 |
RUN mkdir -p /app/data/configs /app/data/uploads /app/data/results && \
|
39 |
chmod -R 777 /app/data
|
40 |
|
41 |
-
# Copy and run the NLTK fix script
|
42 |
-
COPY fix_nltk_permissions.py .
|
43 |
-
RUN python fix_nltk_permissions.py
|
44 |
-
|
45 |
# Copy universal metrics YAML file
|
46 |
COPY universal_metrics.yaml /app/data/configs/
|
47 |
|
|
|
38 |
RUN mkdir -p /app/data/configs /app/data/uploads /app/data/results && \
|
39 |
chmod -R 777 /app/data
|
40 |
|
|
|
|
|
|
|
|
|
41 |
# Copy universal metrics YAML file
|
42 |
COPY universal_metrics.yaml /app/data/configs/
|
43 |
|
fix_nltk_permissions.py
DELETED
@@ -1,81 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python3
|
2 |
-
"""
|
3 |
-
Script to pre-download NLTK data to a writable location and patch
|
4 |
-
discrete_speech_metrics to use this location.
|
5 |
-
"""
|
6 |
-
|
7 |
-
import os
|
8 |
-
import sys
|
9 |
-
import nltk
|
10 |
-
import importlib.util
|
11 |
-
import subprocess
|
12 |
-
|
13 |
-
# Set NLTK data directory to a writable location
|
14 |
-
nltk_data_dir = "/usr/local/share/nltk_data"
|
15 |
-
os.makedirs(nltk_data_dir, exist_ok=True)
|
16 |
-
os.environ["NLTK_DATA"] = nltk_data_dir
|
17 |
-
|
18 |
-
print(f"Setting NLTK data directory to: {nltk_data_dir}")
|
19 |
-
print(f"Directory exists: {os.path.exists(nltk_data_dir)}")
|
20 |
-
print(f"Directory permissions: {oct(os.stat(nltk_data_dir).st_mode)}")
|
21 |
-
print(f"User ID: {os.getuid()}, Group ID: {os.getgid()}")
|
22 |
-
|
23 |
-
# Make the directory world-writable
|
24 |
-
try:
|
25 |
-
os.chmod(nltk_data_dir, 0o777)
|
26 |
-
print(f"Changed permissions on {nltk_data_dir} to 0o777")
|
27 |
-
except Exception as e:
|
28 |
-
print(f"Failed to change permissions: {e}")
|
29 |
-
|
30 |
-
# Pre-download necessary NLTK data
|
31 |
-
for package in ['punkt', 'stopwords', 'wordnet']:
|
32 |
-
print(f"Downloading NLTK package: {package}")
|
33 |
-
try:
|
34 |
-
nltk.download(package, download_dir=nltk_data_dir, quiet=False)
|
35 |
-
print(f"Successfully downloaded {package}")
|
36 |
-
except Exception as e:
|
37 |
-
print(f"Error downloading {package}: {e}")
|
38 |
-
|
39 |
-
# Try to modify the discrete_speech_metrics module to use our NLTK data dir
|
40 |
-
try:
|
41 |
-
# Find discrete_speech_metrics module
|
42 |
-
spec = importlib.util.find_spec("discrete_speech_metrics")
|
43 |
-
if spec is not None:
|
44 |
-
module_path = os.path.dirname(spec.origin)
|
45 |
-
print(f"Found discrete_speech_metrics at: {module_path}")
|
46 |
-
|
47 |
-
# Files to patch
|
48 |
-
files_to_patch = [
|
49 |
-
os.path.join(module_path, "speechbleu.py"),
|
50 |
-
os.path.join(module_path, "speechbert.py"),
|
51 |
-
os.path.join(module_path, "__init__.py")
|
52 |
-
]
|
53 |
-
|
54 |
-
for file_path in files_to_patch:
|
55 |
-
if os.path.exists(file_path):
|
56 |
-
print(f"Patching file: {file_path}")
|
57 |
-
|
58 |
-
# Read file content
|
59 |
-
with open(file_path, 'r') as file:
|
60 |
-
content = file.read()
|
61 |
-
|
62 |
-
# Replace nltk.download with our custom version
|
63 |
-
if "nltk.download" in content:
|
64 |
-
patched_content = content.replace(
|
65 |
-
'nltk.download(',
|
66 |
-
f'nltk.download(download_dir="{nltk_data_dir}", '
|
67 |
-
)
|
68 |
-
|
69 |
-
# Write patched content back
|
70 |
-
with open(file_path, 'w') as file:
|
71 |
-
file.write(patched_content)
|
72 |
-
|
73 |
-
print(f"Successfully patched {file_path}")
|
74 |
-
else:
|
75 |
-
print(f"No nltk.download calls found in {file_path}")
|
76 |
-
else:
|
77 |
-
print("discrete_speech_metrics module not found")
|
78 |
-
except Exception as e:
|
79 |
-
print(f"Error patching discrete_speech_metrics: {e}")
|
80 |
-
|
81 |
-
print("NLTK setup complete")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|