Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from flask import Flask, render_template, redirect, url_for, request
|
2 |
import csv
|
3 |
import requests
|
4 |
import os
|
@@ -25,11 +25,13 @@ def load_translations(filename):
|
|
25 |
"yi": row["yi"],
|
26 |
"likes": 0,
|
27 |
"dislikes": 0,
|
28 |
-
|
29 |
-
})
|
30 |
return translations
|
31 |
|
32 |
translations = load_translations('translations.csv') # Votre dataset au format csv
|
|
|
|
|
|
|
33 |
|
34 |
@app.route('/')
|
35 |
def index():
|
@@ -48,7 +50,7 @@ def vote(id, action):
|
|
48 |
@app.route('/submit_feedback/<int:id>', methods=['POST'])
|
49 |
def submit_feedback(id):
|
50 |
translation = next((t for t in translations if t["id"] == id), None)
|
51 |
-
if translation
|
52 |
feedback = request.form['feedback']
|
53 |
message = f"Feedback sur la traduction #{translation['id']}:\n\n" \
|
54 |
f"Français: {translation['fr']}\n\n" \
|
@@ -61,10 +63,10 @@ def submit_feedback(id):
|
|
61 |
}
|
62 |
response = requests.post(TELEGRAM_API_URL, params=params)
|
63 |
if response.status_code == 200:
|
64 |
-
|
65 |
else:
|
66 |
print(f"Error sending message to Telegram. Status code: {response.status_code}, Response: {response.text}")
|
67 |
-
|
68 |
return redirect(url_for('index'))
|
69 |
|
70 |
|
|
|
1 |
+
from flask import Flask, render_template, redirect, url_for, request, jsonify
|
2 |
import csv
|
3 |
import requests
|
4 |
import os
|
|
|
25 |
"yi": row["yi"],
|
26 |
"likes": 0,
|
27 |
"dislikes": 0,
|
28 |
+
})
|
|
|
29 |
return translations
|
30 |
|
31 |
translations = load_translations('translations.csv') # Votre dataset au format csv
|
32 |
+
@app.route('/data')
|
33 |
+
def data():
|
34 |
+
return jsonify(translations=translations)
|
35 |
|
36 |
@app.route('/')
|
37 |
def index():
|
|
|
50 |
@app.route('/submit_feedback/<int:id>', methods=['POST'])
|
51 |
def submit_feedback(id):
|
52 |
translation = next((t for t in translations if t["id"] == id), None)
|
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" \
|
|
|
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 |
|