Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,13 @@ from flask import Flask, render_template, request, jsonify
|
|
| 2 |
from flask_cors import CORS
|
| 3 |
from gtts import gTTS
|
| 4 |
from langdetect import detect
|
| 5 |
-
from gofile import Gofile
|
| 6 |
import os
|
| 7 |
import tempfile
|
|
|
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
CORS(app)
|
| 11 |
|
| 12 |
-
# Словарь с названиями языков
|
| 13 |
language_names = {
|
| 14 |
'ru': 'Русский',
|
| 15 |
'en': 'Английский',
|
|
@@ -136,6 +135,18 @@ language_names = {
|
|
| 136 |
'ko': 'Корейский',
|
| 137 |
}
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
@app.route('/', methods=['GET', 'POST'])
|
| 140 |
def index():
|
| 141 |
if request.method == 'POST':
|
|
@@ -151,11 +162,9 @@ def index():
|
|
| 151 |
tts.save(temp_file.name)
|
| 152 |
|
| 153 |
# Загрузка файла на Gofile
|
| 154 |
-
|
| 155 |
-
upload_result = gofile_client.upload(temp_file.name)
|
| 156 |
|
| 157 |
-
if
|
| 158 |
-
file_url = upload_result['data']['downloadPage']
|
| 159 |
return jsonify({"status": "success", "url": file_url})
|
| 160 |
else:
|
| 161 |
return jsonify({"status": "error", "message": "Ошибка загрузки файла"})
|
|
|
|
| 2 |
from flask_cors import CORS
|
| 3 |
from gtts import gTTS
|
| 4 |
from langdetect import detect
|
|
|
|
| 5 |
import os
|
| 6 |
import tempfile
|
| 7 |
+
import requests
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
CORS(app)
|
| 11 |
|
|
|
|
| 12 |
language_names = {
|
| 13 |
'ru': 'Русский',
|
| 14 |
'en': 'Английский',
|
|
|
|
| 135 |
'ko': 'Корейский',
|
| 136 |
}
|
| 137 |
|
| 138 |
+
def upload_to_gofile(file_path):
|
| 139 |
+
with open(file_path, 'rb') as file:
|
| 140 |
+
response = requests.post(
|
| 141 |
+
'https://api.gofile.io/uploadFile',
|
| 142 |
+
files={'file': file}
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
if response.status_code == 200 and response.json()['status'] == 'ok':
|
| 146 |
+
return response.json()['data']['downloadPage']
|
| 147 |
+
else:
|
| 148 |
+
return None
|
| 149 |
+
|
| 150 |
@app.route('/', methods=['GET', 'POST'])
|
| 151 |
def index():
|
| 152 |
if request.method == 'POST':
|
|
|
|
| 162 |
tts.save(temp_file.name)
|
| 163 |
|
| 164 |
# Загрузка файла на Gofile
|
| 165 |
+
file_url = upload_to_gofile(temp_file.name)
|
|
|
|
| 166 |
|
| 167 |
+
if file_url:
|
|
|
|
| 168 |
return jsonify({"status": "success", "url": file_url})
|
| 169 |
else:
|
| 170 |
return jsonify({"status": "error", "message": "Ошибка загрузки файла"})
|