Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
-
from flask import Flask, render_template, redirect, url_for, request
|
2 |
import csv
|
3 |
-
import requests
|
4 |
import os
|
5 |
from dotenv import load_dotenv
|
6 |
|
@@ -8,11 +7,6 @@ load_dotenv()
|
|
8 |
|
9 |
app = Flask(__name__)
|
10 |
|
11 |
-
# Configuration Telegram
|
12 |
-
BOT_TOKEN = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A"
|
13 |
-
CHAT_ID = "-1002081124539"
|
14 |
-
TELEGRAM_API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
|
15 |
-
|
16 |
# Chargement du dataset de traductions
|
17 |
def load_translations(filename):
|
18 |
translations = []
|
@@ -25,13 +19,11 @@ def load_translations(filename):
|
|
25 |
"yi": row["yi"],
|
26 |
"likes": 0,
|
27 |
"dislikes": 0,
|
28 |
-
|
|
|
29 |
return translations
|
30 |
|
31 |
-
translations = load_translations('translations.csv')
|
32 |
-
@app.route('/data')
|
33 |
-
def data():
|
34 |
-
return jsonify(translations=translations)
|
35 |
|
36 |
@app.route('/')
|
37 |
def index():
|
@@ -45,29 +37,13 @@ def vote(id, action):
|
|
45 |
translation["likes"] += 1
|
46 |
elif action == "dislike":
|
47 |
translation["dislikes"] += 1
|
|
|
|
|
48 |
return redirect(url_for('index'))
|
49 |
|
50 |
@app.route('/submit_feedback/<int:id>', methods=['POST'])
|
51 |
def submit_feedback(id):
|
52 |
-
|
53 |
-
if translation:
|
54 |
-
feedback = request.form['feedback']
|
55 |
-
message = f"Feedback sur la traduction #{translation['id']}:\n\n" \
|
56 |
-
f"Français: {translation['fr']}\n\n" \
|
57 |
-
f"Yipunu: {translation['yi']}\n\n" \
|
58 |
-
f"Avis de l'utilisateur:\n{feedback}"
|
59 |
-
params = {
|
60 |
-
"chat_id": CHAT_ID,
|
61 |
-
"text": message,
|
62 |
-
"parse_mode": "HTML"
|
63 |
-
}
|
64 |
-
response = requests.post(TELEGRAM_API_URL, params=params)
|
65 |
-
if response.status_code == 200:
|
66 |
-
return jsonify({"message": "Feedback sent succesfully"})
|
67 |
-
else:
|
68 |
-
print(f"Error sending message to Telegram. Status code: {response.status_code}, Response: {response.text}")
|
69 |
-
return jsonify({"message": "Error sending message to Telegram"}), 500
|
70 |
-
return redirect(url_for('index'))
|
71 |
|
72 |
|
73 |
if __name__ == '__main__':
|
|
|
1 |
+
from flask import Flask, render_template, redirect, url_for, request
|
2 |
import csv
|
|
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
5 |
|
|
|
7 |
|
8 |
app = Flask(__name__)
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
# Chargement du dataset de traductions
|
11 |
def load_translations(filename):
|
12 |
translations = []
|
|
|
19 |
"yi": row["yi"],
|
20 |
"likes": 0,
|
21 |
"dislikes": 0,
|
22 |
+
"feedback_sent": False
|
23 |
+
})
|
24 |
return translations
|
25 |
|
26 |
+
translations = load_translations('translations.csv') # Votre dataset au format csv
|
|
|
|
|
|
|
27 |
|
28 |
@app.route('/')
|
29 |
def index():
|
|
|
37 |
translation["likes"] += 1
|
38 |
elif action == "dislike":
|
39 |
translation["dislikes"] += 1
|
40 |
+
elif action == "submit":
|
41 |
+
translation["feedback_sent"] = True
|
42 |
return redirect(url_for('index'))
|
43 |
|
44 |
@app.route('/submit_feedback/<int:id>', methods=['POST'])
|
45 |
def submit_feedback(id):
|
46 |
+
return redirect(url_for('index'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
|
49 |
if __name__ == '__main__':
|