from flask import Flask, render_template, request, jsonify from flaskext.markdown import Markdown from markupsafe import Markup import requests import os from config import settings app = Flask(__name__) Markdown(app) def correct_text(text): url = f"{settings.BACKEND_URL}/corriger" response = requests.post(url, json={"text": text}) if response.status_code != 200: return {"error": f"Erreur lors de la requĂȘte au serveur: {response.status_code}"} else: return {"text": response.json()["text"]} @app.route('/') def index(): with open("ressources/header.md", "r") as f: header = f.read() with open("ressources/footer.md", "r") as f: footer = f.read() return render_template('index.html', header=header, footer=footer) @app.route('/correct', methods=['POST']) def correct(): text = request.form['text'] result = correct_text(text) return jsonify(result) if __name__ == '__main__': debug_mode = os.getenv('FLASK_DEBUG', 'False').lower() == 'true' app.run(host='localhost', debug=debug_mode)