Update app.py
Browse files
app.py
CHANGED
@@ -146,27 +146,28 @@ def index():
|
|
146 |
language_code = detect(input_text)
|
147 |
|
148 |
tts = gTTS(text=input_text, lang=language_code, slow=False)
|
149 |
-
|
150 |
-
|
|
|
151 |
|
152 |
gofile_server = get_gofile_server()
|
153 |
if not gofile_server:
|
154 |
return jsonify({"status": "error", "message": "Не удалось получить сервер Gofile"})
|
155 |
|
156 |
upload_url = f"https://{gofile_server}.gofile.io/uploadFile"
|
157 |
-
|
158 |
-
with open(
|
159 |
-
files = {"file": (os.path.basename(
|
160 |
response = requests.post(upload_url, files=files)
|
161 |
|
162 |
-
os.remove(
|
163 |
|
164 |
if response.status_code == 200:
|
165 |
uploaded_data = response.json()['data']
|
166 |
return jsonify({"status": "success", "url": uploaded_data['downloadPage']})
|
167 |
else:
|
168 |
return jsonify({"status": "error", "message": "Ошибка при загрузке файла на сервер"})
|
169 |
-
|
170 |
return render_template('index.html')
|
171 |
|
172 |
@app.route('/language', methods=['GET', 'POST'])
|
|
|
146 |
language_code = detect(input_text)
|
147 |
|
148 |
tts = gTTS(text=input_text, lang=language_code, slow=False)
|
149 |
+
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
150 |
+
tts.save(temp_file.name)
|
151 |
+
temp_file_path = temp_file.name
|
152 |
|
153 |
gofile_server = get_gofile_server()
|
154 |
if not gofile_server:
|
155 |
return jsonify({"status": "error", "message": "Не удалось получить сервер Gofile"})
|
156 |
|
157 |
upload_url = f"https://{gofile_server}.gofile.io/uploadFile"
|
158 |
+
|
159 |
+
with open(temp_file_path, "rb") as file:
|
160 |
+
files = {"file": (os.path.basename(temp_file_path), file)}
|
161 |
response = requests.post(upload_url, files=files)
|
162 |
|
163 |
+
os.remove(temp_file_path)
|
164 |
|
165 |
if response.status_code == 200:
|
166 |
uploaded_data = response.json()['data']
|
167 |
return jsonify({"status": "success", "url": uploaded_data['downloadPage']})
|
168 |
else:
|
169 |
return jsonify({"status": "error", "message": "Ошибка при загрузке файла на сервер"})
|
170 |
+
|
171 |
return render_template('index.html')
|
172 |
|
173 |
@app.route('/language', methods=['GET', 'POST'])
|