Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,45 +36,43 @@ GOOGLE_API_KEY = os.environ.get("TOKEN")
|
|
| 36 |
genai.configure(api_key=GOOGLE_API_KEY)
|
| 37 |
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
"""Génère une section de dissertation d'histoire."""
|
| 43 |
-
prompt = f"""
|
| 44 |
-
je souhaite faire mon travail d'histoire. le thème c'est {thème} et les différents point a détaillé sont : {point}
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
Introduction
|
| 49 |
-
Amorce
|
| 50 |
-
Problématique
|
| 51 |
Annonce du plan(les points )
|
| 52 |
|
| 53 |
Développement(il y a trois points et donc une partie pour chaque points )
|
| 54 |
|
| 55 |
-
1er partie
|
| 56 |
|
| 57 |
-
Phrase chapeau
|
| 58 |
-
Argument 1
|
| 59 |
-
Argument 2
|
| 60 |
-
Transition
|
| 61 |
|
| 62 |
2eme partie
|
| 63 |
|
| 64 |
-
Phrase chapeau
|
| 65 |
-
Argument 1+ explication+ exemple
|
| 66 |
-
Argument 2 + explication + exemple
|
| 67 |
-
Transition
|
| 68 |
|
| 69 |
3eme partie
|
| 70 |
|
| 71 |
-
Phrase chapeau
|
| 72 |
-
Argument 1+ explication
|
| 73 |
-
Argument 2 + explication + exemple
|
| 74 |
|
| 75 |
Conclusion
|
| 76 |
|
| 77 |
-
|
| 78 |
"""
|
| 79 |
|
| 80 |
model = genai.GenerativeModel('gemini-exp-1206',generation_config=generation_config, safety_settings=safety_settings)
|
|
@@ -82,94 +80,13 @@ Conclusion
|
|
| 82 |
return response.text
|
| 83 |
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
@app.route('/')
|
| 89 |
def index():
|
| 90 |
return render_template('histoire.html')
|
| 91 |
|
| 92 |
|
| 93 |
-
def rediger_section_histoire(theme, point, contexte_precedent=""):
|
| 94 |
-
"""Génère une section de dissertation d'histoire."""
|
| 95 |
-
prompt = f"""
|
| 96 |
-
Rédige une section détaillée pour une dissertation d'histoire sur le thème "{theme}".
|
| 97 |
-
|
| 98 |
-
Point à traiter: {point}
|
| 99 |
-
|
| 100 |
-
Structure à suivre:
|
| 101 |
-
1. Phrase chapeau introduisant l'idée principale
|
| 102 |
-
2. Trois arguments développés:
|
| 103 |
-
- Argument + Explication détaillée + Exemple
|
| 104 |
-
3. transition vers le point suivant
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
Contexte précédent de la dissertation: {contexte_precedent}
|
| 109 |
-
"""
|
| 110 |
-
|
| 111 |
-
model = genai.GenerativeModel('gemini-1.5-flash-002',generation_config=generation_config, safety_settings=safety_settings)
|
| 112 |
-
chat = model.start_chat()
|
| 113 |
-
response = chat.send_message(prompt)
|
| 114 |
-
return response.text, chat.history
|
| 115 |
-
|
| 116 |
-
def rediger_section_geographie(theme, point, contexte_precedent=""):
|
| 117 |
-
"""Génère une section de dissertation de géographie."""
|
| 118 |
-
prompt = f"""
|
| 119 |
-
Rédige une section détaillée pour une dissertation de géographie sur le thème "{theme}".
|
| 120 |
-
|
| 121 |
-
Point à traiter: {point}
|
| 122 |
-
|
| 123 |
-
Structure à suivre:
|
| 124 |
-
1. Phrase chapeau présentant l'enjeu géographique
|
| 125 |
-
2. Trois aspects à développer:
|
| 126 |
-
- Analyse spatiale + Exemple territorial concret + Données chiffrées
|
| 127 |
-
- Utiliser des échelles d'analyse variées (locale, régionale, mondiale)
|
| 128 |
-
3. Phrase de transition
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
Contexte précédent de la dissertation: {contexte_precedent}
|
| 132 |
-
"""
|
| 133 |
-
|
| 134 |
-
model = genai.GenerativeModel('gemini-1.5-flash-002',generation_config=generation_config, safety_settings=safety_settings)
|
| 135 |
-
chat = model.start_chat()
|
| 136 |
-
response = chat.send_message(prompt)
|
| 137 |
-
return response.text, chat.history
|
| 138 |
-
|
| 139 |
-
def generer_introduction(sujet,points, type_sujet="histoire"):
|
| 140 |
-
"""Génère l'introduction de la dissertation."""
|
| 141 |
-
prompt = f"""
|
| 142 |
-
Rédige une introduction structurée pour une dissertation de {type_sujet} sur le sujet:
|
| 143 |
-
"{sujet}"
|
| 144 |
-
|
| 145 |
-
Structure:
|
| 146 |
-
1. Accroche (définition ou contextualisation)
|
| 147 |
-
2. Problématique claire
|
| 148 |
-
3. Annonce du plan({points})
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
"""
|
| 152 |
-
|
| 153 |
-
model = genai.GenerativeModel('gemini-1.5-flash-002',generation_config=generation_config, safety_settings=safety_settings)
|
| 154 |
-
response = model.generate_content(prompt)
|
| 155 |
-
return response.text
|
| 156 |
|
| 157 |
-
|
| 158 |
-
"""Génère la conclusion de la dissertation."""
|
| 159 |
-
prompt = f"""
|
| 160 |
-
À partir de cette dissertation de {type_sujet} sur "{sujet}",
|
| 161 |
-
rédige une conclusion qui:
|
| 162 |
-
1. Synthétise les points principaux
|
| 163 |
-
2. Répond à la problématique
|
| 164 |
-
3. Propose une ouverture pertinente
|
| 165 |
-
|
| 166 |
-
Contenu de la dissertation:
|
| 167 |
-
{contenu}
|
| 168 |
-
"""
|
| 169 |
-
|
| 170 |
-
model = genai.GenerativeModel('gemini-1.5-flash-002',generation_config=generation_config, safety_settings=safety_settings)
|
| 171 |
-
response = model.generate_content(prompt)
|
| 172 |
-
return response.text
|
| 173 |
|
| 174 |
@app.route('/api/histoire', methods=['POST'])
|
| 175 |
def submit_histoire():
|
|
@@ -186,22 +103,9 @@ def submit_histoire():
|
|
| 186 |
|
| 187 |
try:
|
| 188 |
|
| 189 |
-
|
| 190 |
-
# Génération de l'introduction
|
| 191 |
-
dissertation = generer_introduction(sujet,points, "histoire")
|
| 192 |
-
dissertation += "\n\n"
|
| 193 |
|
| 194 |
-
|
| 195 |
-
contexte = dissertation
|
| 196 |
-
for point in points:
|
| 197 |
-
section_texte, _ = rediger_section_histoire(sujet, point, contexte)
|
| 198 |
-
dissertation += section_texte + "\n\n"
|
| 199 |
-
contexte = dissertation
|
| 200 |
-
|
| 201 |
-
# Génération de la conclusion
|
| 202 |
-
dissertation += generer_conclusion(sujet, dissertation, "histoire")
|
| 203 |
-
"""
|
| 204 |
-
rediger_tout(sujet,points)
|
| 205 |
return jsonify({"output": dissertation}), 200
|
| 206 |
|
| 207 |
except Exception as e:
|
|
|
|
| 36 |
genai.configure(api_key=GOOGLE_API_KEY)
|
| 37 |
|
| 38 |
|
| 39 |
+
def generer_histoire(sujet,points):
|
| 40 |
+
|
| 41 |
+
f = """
|
| 42 |
+
je souhaite faire mon travail d'histoire sous forme de dissertation. le thème {sujet} et les différents point a détaillé sont : {points}
|
| 43 |
|
| 44 |
+
Voici la méthodologie que tu devras scrupuleusement respecté pour la dissertation et assure toi d'intégrer les connecteur logique pour débuter les arguments Je veux un travail bien détaillé :
|
| 45 |
|
| 46 |
+
Introduction
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
Amorce
|
| 49 |
+
Problématique
|
|
|
|
|
|
|
|
|
|
| 50 |
Annonce du plan(les points )
|
| 51 |
|
| 52 |
Développement(il y a trois points et donc une partie pour chaque points )
|
| 53 |
|
| 54 |
+
1er partie
|
| 55 |
|
| 56 |
+
Phrase chapeau ( Avec annonce des deux arguments)
|
| 57 |
+
Argument 1+ explication+ exemple
|
| 58 |
+
Argument 2 + explication + exemple
|
| 59 |
+
Transition
|
| 60 |
|
| 61 |
2eme partie
|
| 62 |
|
| 63 |
+
Phrase chapeau ( Avec annonce des deux arguments)
|
| 64 |
+
Argument 1+ explication+ exemple
|
| 65 |
+
Argument 2 + explication + exemple
|
| 66 |
+
Transition
|
| 67 |
|
| 68 |
3eme partie
|
| 69 |
|
| 70 |
+
Phrase chapeau ( Avec annonce des deux arguments)
|
| 71 |
+
Argument 1+ explication+ exemple
|
| 72 |
+
Argument 2 + explication + exemple
|
| 73 |
|
| 74 |
Conclusion
|
| 75 |
|
|
|
|
| 76 |
"""
|
| 77 |
|
| 78 |
model = genai.GenerativeModel('gemini-exp-1206',generation_config=generation_config, safety_settings=safety_settings)
|
|
|
|
| 80 |
return response.text
|
| 81 |
|
| 82 |
|
|
|
|
|
|
|
|
|
|
| 83 |
@app.route('/')
|
| 84 |
def index():
|
| 85 |
return render_template('histoire.html')
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
@app.route('/api/histoire', methods=['POST'])
|
| 92 |
def submit_histoire():
|
|
|
|
| 103 |
|
| 104 |
try:
|
| 105 |
|
| 106 |
+
dissertation = generer_histoire(sujet,points)
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
return jsonify({"output": dissertation}), 200
|
| 110 |
|
| 111 |
except Exception as e:
|