Spaces:
Sleeping
Sleeping
Updated Dockerfile for Hugging Face Spaces deployment
Browse files- Dockerfile +3 -1
- app/server.js +16 -5
Dockerfile
CHANGED
@@ -48,7 +48,9 @@ ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
|
|
48 |
RUN mkdir -p /app/cache/huggingface && \
|
49 |
mkdir -p /app/cache/triton && \
|
50 |
mkdir -p /app/cache/torch_extensions && \
|
51 |
-
|
|
|
|
|
52 |
|
53 |
# Set environment variables for cache directories
|
54 |
ENV HF_HOME=/app/cache/huggingface
|
|
|
48 |
RUN mkdir -p /app/cache/huggingface && \
|
49 |
mkdir -p /app/cache/triton && \
|
50 |
mkdir -p /app/cache/torch_extensions && \
|
51 |
+
mkdir -p /app/public/audio && \
|
52 |
+
chmod -R 777 /app/cache && \
|
53 |
+
chmod -R 777 /app/public/audio
|
54 |
|
55 |
# Set environment variables for cache directories
|
56 |
ENV HF_HOME=/app/cache/huggingface
|
app/server.js
CHANGED
@@ -10,8 +10,17 @@ const app = express();
|
|
10 |
const port = 3000;
|
11 |
|
12 |
const uploadsDir = path.join(__dirname, 'uploads');
|
|
|
|
|
|
|
13 |
if (!fs.existsSync(uploadsDir)) {
|
14 |
-
fs.mkdirSync(uploadsDir
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
16 |
|
17 |
const storage = multer.memoryStorage();
|
@@ -69,9 +78,11 @@ app.post('/save-audio', upload.single('audio'), async (req, res) => {
|
|
69 |
if (response.ok) {
|
70 |
const result = await response.json();
|
71 |
console.log(result);
|
72 |
-
|
|
|
|
|
73 |
sentenceIndex++;
|
74 |
-
res.status(200).json({ audio_path:
|
75 |
} else {
|
76 |
console.error('Failed to process the file via FastAPI');
|
77 |
res.status(500).send('Failed to process the file via FastAPI');
|
@@ -85,7 +96,7 @@ app.post('/save-audio', upload.single('audio'), async (req, res) => {
|
|
85 |
|
86 |
app.get('/concatenate-audio', (req, res) => {
|
87 |
const folderPath = path.join(uploadsDir, getNextFolderNumber().toString());
|
88 |
-
const finalAudioPath = path.join(
|
89 |
const concatCommand = `ffmpeg -y -i "concat:${audioPaths.join('|')}" -acodec copy ${finalAudioPath}`;
|
90 |
exec(concatCommand, (concatError, concatStdout, concatStderr) => {
|
91 |
if (concatError) {
|
@@ -93,7 +104,7 @@ app.get('/concatenate-audio', (req, res) => {
|
|
93 |
return res.status(500).send('Error concatenating audio files');
|
94 |
}
|
95 |
|
96 |
-
res.status(200).json({ audio_path:
|
97 |
});
|
98 |
});
|
99 |
|
|
|
10 |
const port = 3000;
|
11 |
|
12 |
const uploadsDir = path.join(__dirname, 'uploads');
|
13 |
+
const publicDir = path.join(__dirname, 'public');
|
14 |
+
const audioDir = path.join(publicDir, 'audio');
|
15 |
+
|
16 |
if (!fs.existsSync(uploadsDir)) {
|
17 |
+
fs.mkdirSync(uploadsDir);
|
18 |
+
}
|
19 |
+
if (!fs.existsSync(publicDir)) {
|
20 |
+
fs.mkdirSync(publicDir);
|
21 |
+
}
|
22 |
+
if (!fs.existsSync(audioDir)) {
|
23 |
+
fs.mkdirSync(audioDir);
|
24 |
}
|
25 |
|
26 |
const storage = multer.memoryStorage();
|
|
|
78 |
if (response.ok) {
|
79 |
const result = await response.json();
|
80 |
console.log(result);
|
81 |
+
const generatedAudioPath = path.join(audioDir, path.basename(result.audio_path));
|
82 |
+
fs.renameSync(result.audio_path, generatedAudioPath); // Move the file to the public directory
|
83 |
+
audioPaths.push(`/audio/${path.basename(generatedAudioPath)}`);
|
84 |
sentenceIndex++;
|
85 |
+
res.status(200).json({ audio_path: `/audio/${path.basename(generatedAudioPath)}`, translation: result.translation });
|
86 |
} else {
|
87 |
console.error('Failed to process the file via FastAPI');
|
88 |
res.status(500).send('Failed to process the file via FastAPI');
|
|
|
96 |
|
97 |
app.get('/concatenate-audio', (req, res) => {
|
98 |
const folderPath = path.join(uploadsDir, getNextFolderNumber().toString());
|
99 |
+
const finalAudioPath = path.join(audioDir, 'final_audio.wav');
|
100 |
const concatCommand = `ffmpeg -y -i "concat:${audioPaths.join('|')}" -acodec copy ${finalAudioPath}`;
|
101 |
exec(concatCommand, (concatError, concatStdout, concatStderr) => {
|
102 |
if (concatError) {
|
|
|
104 |
return res.status(500).send('Error concatenating audio files');
|
105 |
}
|
106 |
|
107 |
+
res.status(200).json({ audio_path: `/audio/final_audio.wav` });
|
108 |
});
|
109 |
});
|
110 |
|