from flask import Flask, render_template, request, jsonify import google.generativeai as genai import os from PIL import Image import tempfile app = Flask(__name__) # Configuration de l'API Gemini token = os.environ.get("TOKEN") genai.configure(api_key=token) generation_config = { "temperature": 1, "max_output_tokens": 8192, } safety_settings = [ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"}, {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"}, {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"}, {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"}, ] model = genai.GenerativeModel( model_name="gemini-2.0-flash-exp", generation_config=generation_config, safety_settings=safety_settings ) @app.route('/') def index(): return render_template('index.html') @app.route('/api/francais', methods=['POST']) @telegram_notification def gpt_francais(): """Handles French questions.""" french_prompt = request.form.get('sujet', '').strip() choix = request.form.get('choix', '').strip() style = request.form.get('style', '').strip() if not french_prompt: return jsonify({"output": "Veuillez saisir un thème."}), 400 if choix == "discuter": prompt = f""" Je veux faire mon travail de français de niveau lycée sous la forme d'un travail argumentatif. La question du travail est la suivante : "{french_prompt}". Tu devras discuter ce thème. tu utiliseras la méthodologie suivante : # INTRODUCTION: - Approche par constat - Problématique - Annonce du plan # DÉVELOPPEMENT: - Introduction partielle (énonce la thèse) - Argument 1: * Explications * Illustration (exemple + explication) - Argument 2: * Explications * Illustration (exemple + explication) - Argument 3: * Explications * Illustration (exemple + explication) # phrase de Transiton vers la deuxieme partie : - Introduction partielle (énonce l'antithèse) - Argument 1: * Explications * Illustration (exemple + explication) - Argument 2: * Explications * Illustration (exemple + explication) - Argument 3: * Explications * Illustration (exemple + explication) #Conclusion * Bilan * Ouverture du sujet Je veux que tu utilises un style d'écriture {style}.""" else: prompt = f"""Je veux faire mon travail de français de niveau lycé sous la forme d'un travail argumentatif. La question du travail est la suivante : "{french_prompt}". Tu devras {choix} ce thème. tu utiliseras la méthodologie suivante : # INTRODUCTION: - Approche par constat - Problématique - Annonce du plan # DÉVELOPPEMENT: - Phrase chapeau (énonce la thèse) - Argument 1: * Explications * Illustration (exemple + explication) - Argument 2: * Explications * Illustration (exemple + explication) - Argument 3: * Explications * Illustration (exemple + explication) #Conclusion * Bilan (thèse + arguments1 + arguments2+arguments3) * Ouverture du sujet Je veux que tu utilises un style d'écriture {style}.""" try: response = model.generate_content(prompt) return jsonify({"output": response.text}), 200 except Exception as e: return jsonify({"output": str(e)}), 500 @app.route('/api/etude-texte', methods=['POST']) @telegram_notification def gpt_francais_cc(): """Handles text analysis for French (currently under development).""" if 'image' not in request.files: return jsonify({"output": "Aucune image n'a été téléchargée."}), 400 pre_prompt = "Fais un tableau des outils à utiliser pour ce commentaire composé. Je veux les outils, repérage, et interprétation." try: response = "Rend toi dans Mariam je réfléchis" return jsonify({"output": response}), 200 except Exception as e: return jsonify({"output": str(e)}), 500 # Other Routes