Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -58,28 +58,32 @@ def solve():
|
|
58 |
for part in chunk.candidates[0].content.parts:
|
59 |
if hasattr(part, 'thought') and part.thought:
|
60 |
if mode != "thinking":
|
61 |
-
yield
|
62 |
mode = "thinking"
|
63 |
elif hasattr(part, 'executable_code') and part.executable_code:
|
64 |
if mode != "executing_code":
|
65 |
-
yield
|
66 |
mode = "executing_code"
|
67 |
-
|
|
|
|
|
68 |
elif hasattr(part, 'code_execution_result') and part.code_execution_result:
|
69 |
if mode != "code_result":
|
70 |
-
yield
|
71 |
mode = "code_result"
|
72 |
-
|
|
|
|
|
73 |
else:
|
74 |
if mode != "answering":
|
75 |
-
yield
|
76 |
mode = "answering"
|
77 |
if hasattr(part, 'text') and part.text:
|
78 |
-
yield
|
79 |
|
80 |
except Exception as e:
|
81 |
print(f"Error during generation: {e}")
|
82 |
-
yield
|
83 |
|
84 |
return Response(
|
85 |
stream_with_context(generate()),
|
@@ -125,28 +129,32 @@ def solved():
|
|
125 |
for part in chunk.candidates[0].content.parts:
|
126 |
if hasattr(part, 'thought') and part.thought:
|
127 |
if mode != "thinking":
|
128 |
-
yield
|
129 |
mode = "thinking"
|
130 |
elif hasattr(part, 'executable_code') and part.executable_code:
|
131 |
if mode != "executing_code":
|
132 |
-
yield
|
133 |
mode = "executing_code"
|
134 |
-
|
|
|
|
|
135 |
elif hasattr(part, 'code_execution_result') and part.code_execution_result:
|
136 |
if mode != "code_result":
|
137 |
-
yield
|
138 |
mode = "code_result"
|
139 |
-
|
|
|
|
|
140 |
else:
|
141 |
if mode != "answering":
|
142 |
-
yield
|
143 |
mode = "answering"
|
144 |
if hasattr(part, 'text') and part.text:
|
145 |
-
yield
|
146 |
|
147 |
except Exception as e:
|
148 |
print(f"Error during generation: {e}")
|
149 |
-
yield
|
150 |
|
151 |
return Response(
|
152 |
stream_with_context(generate()),
|
|
|
58 |
for part in chunk.candidates[0].content.parts:
|
59 |
if hasattr(part, 'thought') and part.thought:
|
60 |
if mode != "thinking":
|
61 |
+
yield '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 'data: ' + json.dumps({"mode": "executing_code"}) + '\n\n'
|
66 |
mode = "executing_code"
|
67 |
+
code_block_open = "```python\n"
|
68 |
+
code_block_close = "\n```"
|
69 |
+
yield 'data: ' + json.dumps({"content": code_block_open + part.executable_code.code + code_block_close}) + '\n\n'
|
70 |
elif hasattr(part, 'code_execution_result') and part.code_execution_result:
|
71 |
if mode != "code_result":
|
72 |
+
yield 'data: ' + json.dumps({"mode": "code_result"}) + '\n\n'
|
73 |
mode = "code_result"
|
74 |
+
result_block_open = "Résultat d'exécution:\n```\n"
|
75 |
+
result_block_close = "\n```"
|
76 |
+
yield 'data: ' + json.dumps({"content": result_block_open + part.code_execution_result.output + result_block_close}) + '\n\n'
|
77 |
else:
|
78 |
if mode != "answering":
|
79 |
+
yield 'data: ' + json.dumps({"mode": "answering"}) + '\n\n'
|
80 |
mode = "answering"
|
81 |
if hasattr(part, 'text') and part.text:
|
82 |
+
yield 'data: ' + json.dumps({"content": part.text}) + '\n\n'
|
83 |
|
84 |
except Exception as e:
|
85 |
print(f"Error during generation: {e}")
|
86 |
+
yield 'data: ' + json.dumps({"error": str(e)}) + '\n\n'
|
87 |
|
88 |
return Response(
|
89 |
stream_with_context(generate()),
|
|
|
129 |
for part in chunk.candidates[0].content.parts:
|
130 |
if hasattr(part, 'thought') and part.thought:
|
131 |
if mode != "thinking":
|
132 |
+
yield 'data: ' + json.dumps({"mode": "thinking"}) + '\n\n'
|
133 |
mode = "thinking"
|
134 |
elif hasattr(part, 'executable_code') and part.executable_code:
|
135 |
if mode != "executing_code":
|
136 |
+
yield 'data: ' + json.dumps({"mode": "executing_code"}) + '\n\n'
|
137 |
mode = "executing_code"
|
138 |
+
code_block_open = "```python\n"
|
139 |
+
code_block_close = "\n```"
|
140 |
+
yield 'data: ' + json.dumps({"content": code_block_open + part.executable_code.code + code_block_close}) + '\n\n'
|
141 |
elif hasattr(part, 'code_execution_result') and part.code_execution_result:
|
142 |
if mode != "code_result":
|
143 |
+
yield 'data: ' + json.dumps({"mode": "code_result"}) + '\n\n'
|
144 |
mode = "code_result"
|
145 |
+
result_block_open = "Résultat d'exécution:\n```\n"
|
146 |
+
result_block_close = "\n```"
|
147 |
+
yield 'data: ' + json.dumps({"content": result_block_open + part.code_execution_result.output + result_block_close}) + '\n\n'
|
148 |
else:
|
149 |
if mode != "answering":
|
150 |
+
yield 'data: ' + json.dumps({"mode": "answering"}) + '\n\n'
|
151 |
mode = "answering"
|
152 |
if hasattr(part, 'text') and part.text:
|
153 |
+
yield 'data: ' + json.dumps({"content": part.text}) + '\n\n'
|
154 |
|
155 |
except Exception as e:
|
156 |
print(f"Error during generation: {e}")
|
157 |
+
yield 'data: ' + json.dumps({"error": str(e)}) + '\n\n'
|
158 |
|
159 |
return Response(
|
160 |
stream_with_context(generate()),
|