Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
import os
|
2 |
import base64
|
3 |
-
from flask import Flask, request, jsonify, send_file
|
4 |
import google.generativeai as genai
|
5 |
from gtts import gTTS, lang
|
6 |
import tempfile
|
7 |
import soundfile as sf
|
8 |
-
from kokoro import KPipeline
|
9 |
from werkzeug.utils import secure_filename
|
10 |
from flask_cors import CORS
|
11 |
|
@@ -60,8 +59,8 @@ def translate_audio():
|
|
60 |
audio_file.save(temp_input_path)
|
61 |
|
62 |
# Read audio file as base64
|
63 |
-
with open(temp_input_path, "rb") as
|
64 |
-
audio_data = base64.b64encode(
|
65 |
|
66 |
# Transcribe with Gemini
|
67 |
model = genai.GenerativeModel("gemini-1.5-pro-latest")
|
@@ -89,12 +88,9 @@ def translate_audio():
|
|
89 |
# Generate TTS
|
90 |
if target_language in KOKORO_LANGUAGES:
|
91 |
lang_code = KOKORO_LANGUAGES[target_language]
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
if audio_data:
|
96 |
-
_, temp_output_path = tempfile.mkstemp(suffix=".wav")
|
97 |
-
sf.write(temp_output_path, audio_data, 24000)
|
98 |
else:
|
99 |
lang_code = next((k for k, v in GTTS_LANGUAGES.items() if v == target_language), 'en')
|
100 |
tts = gTTS(translated_text, lang=lang_code)
|
@@ -108,7 +104,6 @@ def translate_audio():
|
|
108 |
})
|
109 |
|
110 |
except Exception as e:
|
111 |
-
app.logger.error(f"Error processing request: {str(e)}")
|
112 |
return jsonify({'error': str(e)}), 500
|
113 |
|
114 |
@app.route('/download/<filename>')
|
@@ -124,4 +119,4 @@ def download_file(filename):
|
|
124 |
return jsonify({'error': 'File not found'}), 404
|
125 |
|
126 |
if __name__ == '__main__':
|
127 |
-
app.run(host=
|
|
|
1 |
import os
|
2 |
import base64
|
3 |
+
from flask import Flask, request, jsonify, send_file, send_from_directory
|
4 |
import google.generativeai as genai
|
5 |
from gtts import gTTS, lang
|
6 |
import tempfile
|
7 |
import soundfile as sf
|
|
|
8 |
from werkzeug.utils import secure_filename
|
9 |
from flask_cors import CORS
|
10 |
|
|
|
59 |
audio_file.save(temp_input_path)
|
60 |
|
61 |
# Read audio file as base64
|
62 |
+
with open(temp_input_path, "rb") as f:
|
63 |
+
audio_data = base64.b64encode(f.read()).decode("utf-8")
|
64 |
|
65 |
# Transcribe with Gemini
|
66 |
model = genai.GenerativeModel("gemini-1.5-pro-latest")
|
|
|
88 |
# Generate TTS
|
89 |
if target_language in KOKORO_LANGUAGES:
|
90 |
lang_code = KOKORO_LANGUAGES[target_language]
|
91 |
+
# Kokoro TTS implementation
|
92 |
+
_, temp_output_path = tempfile.mkstemp(suffix=".wav")
|
93 |
+
# Add actual Kokoro synthesis here
|
|
|
|
|
|
|
94 |
else:
|
95 |
lang_code = next((k for k, v in GTTS_LANGUAGES.items() if v == target_language), 'en')
|
96 |
tts = gTTS(translated_text, lang=lang_code)
|
|
|
104 |
})
|
105 |
|
106 |
except Exception as e:
|
|
|
107 |
return jsonify({'error': str(e)}), 500
|
108 |
|
109 |
@app.route('/download/<filename>')
|
|
|
119 |
return jsonify({'error': 'File not found'}), 404
|
120 |
|
121 |
if __name__ == '__main__':
|
122 |
+
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))
|