Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import os
|
|
3 |
import google.generativeai as genai
|
4 |
import time
|
5 |
import asyncio
|
|
|
6 |
app = Flask(__name__)
|
7 |
|
8 |
# Configuration
|
@@ -10,6 +11,14 @@ token = os.environ.get("TOKEN")
|
|
10 |
if not token:
|
11 |
raise ValueError("La variable d'environnement TOKEN n'est pas définie.")
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
genai.configure(api_key=token)
|
14 |
|
15 |
generation_config = {
|
@@ -140,12 +149,24 @@ def index():
|
|
140 |
return jsonify({'translated_text': translated_text})
|
141 |
return render_template('traduction.html', source_languages=source_languages, target_languages=target_languages)
|
142 |
|
|
|
143 |
@app.route('/free', methods=['GET', 'POST'])
|
144 |
def free():
|
145 |
-
|
|
|
|
|
|
|
|
|
146 |
|
|
|
|
|
147 |
|
|
|
|
|
148 |
|
|
|
|
|
|
|
149 |
|
150 |
if __name__ == '__main__':
|
151 |
app.run(debug=True)
|
|
|
3 |
import google.generativeai as genai
|
4 |
import time
|
5 |
import asyncio
|
6 |
+
import telegram
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
# Configuration
|
|
|
11 |
if not token:
|
12 |
raise ValueError("La variable d'environnement TOKEN n'est pas définie.")
|
13 |
|
14 |
+
|
15 |
+
BOT_TOKEN = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A"
|
16 |
+
CHAT_ID = "-1002081124539"
|
17 |
+
|
18 |
+
bot = telegram.Bot(token=BOT_TOKEN)
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
genai.configure(api_key=token)
|
23 |
|
24 |
generation_config = {
|
|
|
149 |
return jsonify({'translated_text': translated_text})
|
150 |
return render_template('traduction.html', source_languages=source_languages, target_languages=target_languages)
|
151 |
|
152 |
+
|
153 |
@app.route('/free', methods=['GET', 'POST'])
|
154 |
def free():
|
155 |
+
if request.method == 'POST':
|
156 |
+
french_word = request.form['french_word']
|
157 |
+
translated_word = request.form['translated_word']
|
158 |
+
target_language = request.form['target_language']
|
159 |
+
audio_file = request.files.get('audio_file')
|
160 |
|
161 |
+
message = f"Nouvelle soumission :\nFrançais : {french_word}\nTraduction ({target_language}) : {translated_word}"
|
162 |
+
bot.send_message(chat_id=TELEGRAM_GROUP_ID, text=message)
|
163 |
|
164 |
+
if audio_file:
|
165 |
+
bot.send_audio(chat_id=TELEGRAM_GROUP_ID, audio=audio_file)
|
166 |
|
167 |
+
return render_template('free.html', source_languages=source_languages, target_languages=target_languages, message_sent = True)
|
168 |
+
|
169 |
+
return render_template('free.html', source_languages=source_languages, target_languages=target_languages)
|
170 |
|
171 |
if __name__ == '__main__':
|
172 |
app.run(debug=True)
|