yalsaffar commited on
Commit
e6de97c
1 Parent(s): 38ba82a

Updated Dockerfile for Hugging Face Spaces deployment

Browse files
Files changed (2) hide show
  1. app/public/app.js +5 -2
  2. app/server.js +2 -2
app/public/app.js CHANGED
@@ -84,8 +84,11 @@ async function saveAudioAndTranscription(sentence, index) {
84
 
85
  // Show translation and play audio
86
  translationElement.textContent = result.translation;
87
- audioElement.src = `http://localhost:8000/download-audio?file_path=${result.audio_path}`;
88
- audioElement.play();
 
 
 
89
  } else {
90
  console.error('Failed to save the file.');
91
  }
 
84
 
85
  // Show translation and play audio
86
  translationElement.textContent = result.translation;
87
+ audioElement.src = `https://${window.location.hostname}:${window.location.port}/download-audio?file_path=${result.audio_path}`;
88
+ audioElement.load(); // Ensure the audio element loads the new source
89
+ audioElement.play().catch(error => {
90
+ console.error('Error playing audio:', error);
91
+ });
92
  } else {
93
  console.error('Failed to save the file.');
94
  }
app/server.js CHANGED
@@ -78,13 +78,13 @@ app.post('/save-audio', upload.single('audio'), async (req, res) => {
78
  sentenceIndex++;
79
 
80
  // Copy the audio file to the public directory
81
- const publicAudioPath = path.join(publicDir, path.basename(result.audio_path));
82
  fs.copyFile(result.audio_path, publicAudioPath, (err) => {
83
  if (err) {
84
  console.error('Error copying audio file to public directory:', err);
85
  return res.status(500).send('Error copying audio file to public directory');
86
  }
87
- res.status(200).json({ audio_path: `/generated_audio_audio_${sentenceIndex}.wav`, translation: result.translation });
88
  });
89
  } else {
90
  console.error('Failed to process the file via FastAPI');
 
78
  sentenceIndex++;
79
 
80
  // Copy the audio file to the public directory
81
+ const publicAudioPath = path.join(publicDir, `generated_audio_${sentenceIndex}.wav`);
82
  fs.copyFile(result.audio_path, publicAudioPath, (err) => {
83
  if (err) {
84
  console.error('Error copying audio file to public directory:', err);
85
  return res.status(500).send('Error copying audio file to public directory');
86
  }
87
+ res.status(200).json({ audio_path: `generated_audio_${sentenceIndex}.wav`, translation: result.translation });
88
  });
89
  } else {
90
  console.error('Failed to process the file via FastAPI');