Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,10 +6,10 @@ from PIL import Image
|
|
| 6 |
import io
|
| 7 |
import base64
|
| 8 |
import json
|
| 9 |
-
|
| 10 |
app = Flask(__name__)
|
| 11 |
|
| 12 |
-
GOOGLE_API_KEY =
|
| 13 |
|
| 14 |
client = genai.Client(
|
| 15 |
api_key=GOOGLE_API_KEY,
|
|
@@ -17,15 +17,11 @@ client = genai.Client(
|
|
| 17 |
|
| 18 |
@app.route('/')
|
| 19 |
def index():
|
| 20 |
-
#return "La plateforme est en maintenance."
|
| 21 |
return render_template('index.html')
|
| 22 |
|
| 23 |
-
|
| 24 |
@app.route('/free')
|
| 25 |
def indexx():
|
| 26 |
return render_template('maj.html')
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
@app.route('/solve', methods=['POST'])
|
| 31 |
def solve():
|
|
@@ -44,28 +40,42 @@ def solve():
|
|
| 44 |
model="gemini-2.5-pro-exp-03-25",
|
| 45 |
contents=[
|
| 46 |
{'inline_data': {'mime_type': 'image/png', 'data': img_str}},
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
],
|
| 50 |
config=types.GenerateContentConfig(
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
-
|
| 57 |
for chunk in response:
|
| 58 |
for part in chunk.candidates[0].content.parts:
|
| 59 |
-
if part.thought:
|
| 60 |
if mode != "thinking":
|
| 61 |
yield f'data: {json.dumps({"mode": "thinking"})}\n\n'
|
| 62 |
mode = "thinking"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
else:
|
| 64 |
if mode != "answering":
|
| 65 |
yield f'data: {json.dumps({"mode": "answering"})}\n\n'
|
| 66 |
mode = "answering"
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
print(f"Error during generation: {e}")
|
|
@@ -83,8 +93,6 @@ def solve():
|
|
| 83 |
except Exception as e:
|
| 84 |
return jsonify({'error': str(e)}), 500
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
@app.route('/solved', methods=['POST'])
|
| 89 |
def solved():
|
| 90 |
try:
|
|
@@ -102,22 +110,39 @@ def solved():
|
|
| 102 |
model="gemini-2.5-flash-preview-04-17",
|
| 103 |
contents=[
|
| 104 |
{'inline_data': {'mime_type': 'image/png', 'data': img_str}},
|
| 105 |
-
"""
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
)
|
| 108 |
-
|
| 109 |
for chunk in response:
|
| 110 |
for part in chunk.candidates[0].content.parts:
|
| 111 |
-
if part.thought:
|
| 112 |
if mode != "thinking":
|
| 113 |
yield f'data: {json.dumps({"mode": "thinking"})}\n\n'
|
| 114 |
mode = "thinking"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
else:
|
| 116 |
if mode != "answering":
|
| 117 |
yield f'data: {json.dumps({"mode": "answering"})}\n\n'
|
| 118 |
mode = "answering"
|
| 119 |
-
|
| 120 |
-
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
print(f"Error during generation: {e}")
|
|
@@ -134,9 +159,6 @@ def solved():
|
|
| 134 |
|
| 135 |
except Exception as e:
|
| 136 |
return jsonify({'error': str(e)}), 500
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
|
| 141 |
if __name__ == '__main__':
|
| 142 |
app.run(debug=True)
|
|
|
|
| 6 |
import io
|
| 7 |
import base64
|
| 8 |
import json
|
| 9 |
+
|
| 10 |
app = Flask(__name__)
|
| 11 |
|
| 12 |
+
GOOGLE_API_KEY = os.environ.get("GEMINI_API_KEY")
|
| 13 |
|
| 14 |
client = genai.Client(
|
| 15 |
api_key=GOOGLE_API_KEY,
|
|
|
|
| 17 |
|
| 18 |
@app.route('/')
|
| 19 |
def index():
|
|
|
|
| 20 |
return render_template('index.html')
|
| 21 |
|
|
|
|
| 22 |
@app.route('/free')
|
| 23 |
def indexx():
|
| 24 |
return render_template('maj.html')
|
|
|
|
|
|
|
| 25 |
|
| 26 |
@app.route('/solve', methods=['POST'])
|
| 27 |
def solve():
|
|
|
|
| 40 |
model="gemini-2.5-pro-exp-03-25",
|
| 41 |
contents=[
|
| 42 |
{'inline_data': {'mime_type': 'image/png', 'data': img_str}},
|
| 43 |
+
"""Résous cet exercice en français avec du LaTeX.
|
| 44 |
+
Si nécessaire, utilise du code Python pour effectuer les calculs complexes.
|
| 45 |
+
Présente ta solution de façon claire et espacée."""
|
| 46 |
],
|
| 47 |
config=types.GenerateContentConfig(
|
| 48 |
+
thinking_config=types.ThinkingConfig(
|
| 49 |
+
thinking_budget=8000
|
| 50 |
+
),
|
| 51 |
+
tools=[types.Tool(
|
| 52 |
+
code_execution=types.ToolCodeExecution()
|
| 53 |
+
)]
|
| 54 |
+
)
|
| 55 |
)
|
| 56 |
+
|
| 57 |
for chunk in response:
|
| 58 |
for part in chunk.candidates[0].content.parts:
|
| 59 |
+
if hasattr(part, 'thought') and part.thought:
|
| 60 |
if mode != "thinking":
|
| 61 |
yield f'data: {json.dumps({"mode": "thinking"})}\n\n'
|
| 62 |
mode = "thinking"
|
| 63 |
+
elif hasattr(part, 'executable_code') and part.executable_code:
|
| 64 |
+
if mode != "executing_code":
|
| 65 |
+
yield f'data: {json.dumps({"mode": "executing_code"})}\n\n'
|
| 66 |
+
mode = "executing_code"
|
| 67 |
+
yield f'data: {json.dumps({"content": f"```python\n{part.executable_code.code}\n```"})}\n\n'
|
| 68 |
+
elif hasattr(part, 'code_execution_result') and part.code_execution_result:
|
| 69 |
+
if mode != "code_result":
|
| 70 |
+
yield f'data: {json.dumps({"mode": "code_result"})}\n\n'
|
| 71 |
+
mode = "code_result"
|
| 72 |
+
yield f'data: {json.dumps({"content": f"Résultat d'exécution:\n```\n{part.code_execution_result.output}\n```"})}\n\n'
|
| 73 |
else:
|
| 74 |
if mode != "answering":
|
| 75 |
yield f'data: {json.dumps({"mode": "answering"})}\n\n'
|
| 76 |
mode = "answering"
|
| 77 |
+
if hasattr(part, 'text') and part.text:
|
| 78 |
+
yield f'data: {json.dumps({"content": part.text})}\n\n'
|
| 79 |
|
| 80 |
except Exception as e:
|
| 81 |
print(f"Error during generation: {e}")
|
|
|
|
| 93 |
except Exception as e:
|
| 94 |
return jsonify({'error': str(e)}), 500
|
| 95 |
|
|
|
|
|
|
|
| 96 |
@app.route('/solved', methods=['POST'])
|
| 97 |
def solved():
|
| 98 |
try:
|
|
|
|
| 110 |
model="gemini-2.5-flash-preview-04-17",
|
| 111 |
contents=[
|
| 112 |
{'inline_data': {'mime_type': 'image/png', 'data': img_str}},
|
| 113 |
+
"""Résous cet exercice en français avec du LaTeX.
|
| 114 |
+
Si nécessaire, utilise du code Python pour effectuer les calculs complexes.
|
| 115 |
+
Présente ta solution de façon claire et espacée."""
|
| 116 |
+
],
|
| 117 |
+
config=types.GenerateContentConfig(
|
| 118 |
+
tools=[types.Tool(
|
| 119 |
+
code_execution=types.ToolCodeExecution()
|
| 120 |
+
)]
|
| 121 |
+
)
|
| 122 |
)
|
| 123 |
+
|
| 124 |
for chunk in response:
|
| 125 |
for part in chunk.candidates[0].content.parts:
|
| 126 |
+
if hasattr(part, 'thought') and part.thought:
|
| 127 |
if mode != "thinking":
|
| 128 |
yield f'data: {json.dumps({"mode": "thinking"})}\n\n'
|
| 129 |
mode = "thinking"
|
| 130 |
+
elif hasattr(part, 'executable_code') and part.executable_code:
|
| 131 |
+
if mode != "executing_code":
|
| 132 |
+
yield f'data: {json.dumps({"mode": "executing_code"})}\n\n'
|
| 133 |
+
mode = "executing_code"
|
| 134 |
+
yield f'data: {json.dumps({"content": f"```python\n{part.executable_code.code}\n```"})}\n\n'
|
| 135 |
+
elif hasattr(part, 'code_execution_result') and part.code_execution_result:
|
| 136 |
+
if mode != "code_result":
|
| 137 |
+
yield f'data: {json.dumps({"mode": "code_result"})}\n\n'
|
| 138 |
+
mode = "code_result"
|
| 139 |
+
yield f'data: {json.dumps({"content": f"Résultat d'exécution:\n```\n{part.code_execution_result.output}\n```"})}\n\n'
|
| 140 |
else:
|
| 141 |
if mode != "answering":
|
| 142 |
yield f'data: {json.dumps({"mode": "answering"})}\n\n'
|
| 143 |
mode = "answering"
|
| 144 |
+
if hasattr(part, 'text') and part.text:
|
| 145 |
+
yield f'data: {json.dumps({"content": part.text})}\n\n'
|
| 146 |
|
| 147 |
except Exception as e:
|
| 148 |
print(f"Error during generation: {e}")
|
|
|
|
| 159 |
|
| 160 |
except Exception as e:
|
| 161 |
return jsonify({'error': str(e)}), 500
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
if __name__ == '__main__':
|
| 164 |
app.run(debug=True)
|