Docfile commited on
Commit
2a68b81
·
verified ·
1 Parent(s): dc691ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -13
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  from flask import Flask, render_template, request, jsonify, Response, stream_with_context
3
  from google import genai
4
  from google.genai import types
@@ -90,7 +89,7 @@ Provide the improved version of the solution, adhering to the original problem's
90
  **2. How to Handle Issues in the Solution**
91
  When you identify an issue in a step, you MUST first classify it into one of the following two categories and then follow the specified procedure.
92
  * **a. Critical Error:**
93
- This is any error that breaks the logical chain of the proof. This includes both **logical fallacies** (e.g., claiming that A>B, C>D implies A-C>B-D) and **factual errors** (e.g., a calculation error like '2+3=6').
94
  * **Procedure:**
95
  * Explain the specific error and state that it **invalidates the current line of reasoning**.
96
  * Do NOT check any further steps that rely on this error.
@@ -209,43 +208,61 @@ def solve():
209
  current_solution = ""
210
 
211
  # --- Étape 0: Extraction du problème ---
212
- yield f'data: {json.dumps({"content": "### Étape 0 : Extraction de l\'énoncé\nAnalyse de l’image...", "type": "header"})}\n\n'
 
 
 
213
  problem_text = agent_system.extract_problem_text(img_str)
214
- yield f'data: {json.dumps({"content": f"**Énoncé détecté :**\n\n{problem_text}\n\n---\n", "type": "text"})}\n\n'
 
215
 
216
  # --- Pipeline de raisonnement ---
217
  # Étape 1: Solution Initiale
218
- yield f'data: {json.dumps({"content": "### Étape 1 : Génération de la solution initiale\nLe modèle prépare une première version de la preuve...", "type": "header"})}\n\n'
 
 
219
  step1_prompt = agent_system.prompts["step1_initial_solution"] + f"\n\n### Problem ###\n{problem_text}"
220
  current_solution = agent_system.run_agent_step("1 (Initial)", step1_prompt)
221
- yield f'data: {json.dumps({"content": f"**Solution Initiale :**\n\n{current_solution}\n\n---\n", "type": "text"})}\n\n'
 
 
222
 
223
  # Itération de Vérification-Correction (ici, 1 seule itération pour la démo)
224
  MAX_ITERATIONS = 1
225
  for i in range(MAX_ITERATIONS):
226
  # Étape 3: Vérification
227
- yield f'data: {json.dumps({"content": f"### Étape 3.{i+1} : Vérification par l\'expert\nAnalyse critique de la solution pour détecter les erreurs...", "type": "header"})}\n\n'
 
 
228
  step3_prompt = agent_system.prompts["step3_verification"] + f"\n\n### Problem ###\n{problem_text}\n\n### Solution to be verified ###\n{current_solution}"
229
  verification_report = agent_system.run_agent_step(f"3.{i+1} (Verification)", step3_prompt)
230
- yield f'data: {json.dumps({"content": f"**Rapport de vérification :**\n\n{verification_report}\n\n---\n", "type": "text"})}\n\n'
 
 
231
 
232
  # Vérifier si une correction est nécessaire
233
  if "critical error" in verification_report.lower() or "justification gap" in verification_report.lower():
234
  # Étape 5: Correction
235
- yield f'data: {json.dumps({"content": f"### Étape 5.{i+1} : Correction de la solution\nLe modèle utilise le rapport pour corriger sa preuve...", "type": "header"})}\n\n'
 
 
236
  step5_prompt = agent_system.prompts["step5_correction"].replace(
237
  "[The full verification report will be inserted here]", verification_report
238
  ).replace(
239
  "[The previous solution attempt will be inserted here]", current_solution
240
  )
241
  current_solution = agent_system.run_agent_step(f"5.{i+1} (Correction)", step5_prompt)
242
- yield f'data: {json.dumps({"content": f"**Solution Corrigée :**\n\n{current_solution}\n\n---\n", "type": "text"})}\n\n'
 
 
243
  else:
244
- yield f'data: {json.dumps({"content": "✅ Le rapport de vérification n\'a trouvé aucune erreur critique. La solution est considérée comme valide.", "type": "header"})}\n\n'
 
245
  break
246
 
247
  # --- Affichage Final ---
248
- yield f'data: {json.dumps({"content": "# Solution Finale Validée\nVoici la version finale de la correction.", "type": "header"})}\n\n'
 
249
  yield f'data: {json.dumps({"content": current_solution, "type": "final"})}\n\n'
250
 
251
  except Exception as e:
@@ -261,4 +278,4 @@ def solve():
261
  return jsonify({'error': error_message}), 500
262
 
263
  if __name__ == '__main__':
264
- app.run(debug=True)
 
 
1
  from flask import Flask, render_template, request, jsonify, Response, stream_with_context
2
  from google import genai
3
  from google.genai import types
 
89
  **2. How to Handle Issues in the Solution**
90
  When you identify an issue in a step, you MUST first classify it into one of the following two categories and then follow the specified procedure.
91
  * **a. Critical Error:**
92
+ This is any error that breaks the logical chain of the proof. This includes both **logical fallacies** (e.g., claiming that 'A>B, C>D' implies 'A-C>B-D') and **factual errors** (e.g., a calculation error like '2+3=6').
93
  * **Procedure:**
94
  * Explain the specific error and state that it **invalidates the current line of reasoning**.
95
  * Do NOT check any further steps that rely on this error.
 
208
  current_solution = ""
209
 
210
  # --- Étape 0: Extraction du problème ---
211
+ # Fixed: moved the string outside the f-string expression
212
+ step0_msg = "### Étape 0 : Extraction de l'énoncé\nAnalyse de l'image..."
213
+ yield f'data: {json.dumps({"content": step0_msg, "type": "header"})}\n\n'
214
+
215
  problem_text = agent_system.extract_problem_text(img_str)
216
+ problem_msg = f"**Énoncé détecté :**\n\n{problem_text}\n\n---\n"
217
+ yield f'data: {json.dumps({"content": problem_msg, "type": "text"})}\n\n'
218
 
219
  # --- Pipeline de raisonnement ---
220
  # Étape 1: Solution Initiale
221
+ step1_msg = "### Étape 1 : Génération de la solution initiale\nLe modèle prépare une première version de la preuve..."
222
+ yield f'data: {json.dumps({"content": step1_msg, "type": "header"})}\n\n'
223
+
224
  step1_prompt = agent_system.prompts["step1_initial_solution"] + f"\n\n### Problem ###\n{problem_text}"
225
  current_solution = agent_system.run_agent_step("1 (Initial)", step1_prompt)
226
+
227
+ solution1_msg = f"**Solution Initiale :**\n\n{current_solution}\n\n---\n"
228
+ yield f'data: {json.dumps({"content": solution1_msg, "type": "text"})}\n\n'
229
 
230
  # Itération de Vérification-Correction (ici, 1 seule itération pour la démo)
231
  MAX_ITERATIONS = 1
232
  for i in range(MAX_ITERATIONS):
233
  # Étape 3: Vérification
234
+ step3_msg = f"### Étape 3.{i+1} : Vérification par l'expert\nAnalyse critique de la solution pour détecter les erreurs..."
235
+ yield f'data: {json.dumps({"content": step3_msg, "type": "header"})}\n\n'
236
+
237
  step3_prompt = agent_system.prompts["step3_verification"] + f"\n\n### Problem ###\n{problem_text}\n\n### Solution to be verified ###\n{current_solution}"
238
  verification_report = agent_system.run_agent_step(f"3.{i+1} (Verification)", step3_prompt)
239
+
240
+ verification_msg = f"**Rapport de vérification :**\n\n{verification_report}\n\n---\n"
241
+ yield f'data: {json.dumps({"content": verification_msg, "type": "text"})}\n\n'
242
 
243
  # Vérifier si une correction est nécessaire
244
  if "critical error" in verification_report.lower() or "justification gap" in verification_report.lower():
245
  # Étape 5: Correction
246
+ step5_msg = f"### Étape 5.{i+1} : Correction de la solution\nLe modèle utilise le rapport pour corriger sa preuve..."
247
+ yield f'data: {json.dumps({"content": step5_msg, "type": "header"})}\n\n'
248
+
249
  step5_prompt = agent_system.prompts["step5_correction"].replace(
250
  "[The full verification report will be inserted here]", verification_report
251
  ).replace(
252
  "[The previous solution attempt will be inserted here]", current_solution
253
  )
254
  current_solution = agent_system.run_agent_step(f"5.{i+1} (Correction)", step5_prompt)
255
+
256
+ correction_msg = f"**Solution Corrigée :**\n\n{current_solution}\n\n---\n"
257
+ yield f'data: {json.dumps({"content": correction_msg, "type": "text"})}\n\n'
258
  else:
259
+ success_msg = "✅ Le rapport de vérification n'a trouvé aucune erreur critique. La solution est considérée comme valide."
260
+ yield f'data: {json.dumps({"content": success_msg, "type": "header"})}\n\n'
261
  break
262
 
263
  # --- Affichage Final ---
264
+ final_header_msg = "# Solution Finale Validée\nVoici la version finale de la correction."
265
+ yield f'data: {json.dumps({"content": final_header_msg, "type": "header"})}\n\n'
266
  yield f'data: {json.dumps({"content": current_solution, "type": "final"})}\n\n'
267
 
268
  except Exception as e:
 
278
  return jsonify({'error': error_message}), 500
279
 
280
  if __name__ == '__main__':
281
+ app.run(debug=True)