selim-ba commited on
Commit
1995e80
·
verified ·
1 Parent(s): 78b4d99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -11,6 +11,9 @@ import string
11
  import sys
12
  import io
13
  import contextlib
 
 
 
14
 
15
  def code_interpreter(code: str) -> str:
16
  """
@@ -143,21 +146,24 @@ class SuperSmartAgent:
143
  def execute_python_code(self, state):
144
  question = state["question"]
145
 
146
- # Extract code from the question (optional enhancement)
147
- if "```python" in question:
148
- try:
149
- code = question.split("```python")[1].split("```")[0].strip()
150
- except IndexError:
151
- code = ""
152
  else:
153
- # Fallback code
154
  code = """
155
- def calculate():
156
- return 42
 
 
 
 
 
 
 
 
157
 
158
- result = calculate()
159
- print(result)
160
- """
161
  try:
162
  result = code_interpreter(code)
163
  state["response"] = f"Python execution result:\n{result}"
@@ -172,6 +178,7 @@ class SuperSmartAgent:
172
 
173
 
174
 
 
175
  def run_and_submit_all( profile: gr.OAuthProfile | None):
176
  """
177
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
11
  import sys
12
  import io
13
  import contextlib
14
+ import re
15
+ import textwrap
16
+
17
 
18
  def code_interpreter(code: str) -> str:
19
  """
 
146
  def execute_python_code(self, state):
147
  question = state["question"]
148
 
149
+ # Extract code block from ```python ... ```
150
+ code_blocks = re.findall(r"```python(.*?)```", question, re.DOTALL)
151
+ if code_blocks:
152
+ code = code_blocks[0].strip()
 
 
153
  else:
154
+ # Default fallback code
155
  code = """
156
+ def calculate():
157
+ return 42
158
+
159
+ result = calculate()
160
+ print(result)
161
+ """
162
+
163
+ # Clean up indentation
164
+ import textwrap
165
+ code = textwrap.dedent(code).strip()
166
 
 
 
 
167
  try:
168
  result = code_interpreter(code)
169
  state["response"] = f"Python execution result:\n{result}"
 
178
 
179
 
180
 
181
+
182
  def run_and_submit_all( profile: gr.OAuthProfile | None):
183
  """
184
  Fetches all questions, runs the BasicAgent on them, submits all answers,