selim-ba commited on
Commit
412f41f
·
verified ·
1 Parent(s): ed24c31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
app.py CHANGED
@@ -44,6 +44,7 @@ class AgentState(TypedDict):
44
  is_reversed: bool
45
  is_riddle: bool
46
  is_python: bool
 
47
 
48
  class SuperSmartAgent:
49
  def __init__(self):
@@ -144,29 +145,23 @@ class SuperSmartAgent:
144
  return state
145
 
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 5
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"{result}"
170
  except Exception as e:
171
  state["response"] = f"Error executing Python code: {str(e)}"
172
 
@@ -175,10 +170,6 @@ class SuperSmartAgent:
175
 
176
 
177
 
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,
 
44
  is_reversed: bool
45
  is_riddle: bool
46
  is_python: bool
47
+ file_path: str | None
48
 
49
  class SuperSmartAgent:
50
  def __init__(self):
 
145
  return state
146
 
147
  def execute_python_code(self, state):
148
+ file_path = state.get("file_path")
149
+ if file_path and os.path.isfile(file_path):
150
+ try:
151
+ with open(file_path, "r", encoding="utf-8") as f:
152
+ code = f.read()
153
+ code = textwrap.dedent(code).strip()
154
+ except Exception as e:
155
+ state["response"] = f"Error reading file: {str(e)}"
156
+ return state
157
  else:
158
+ # Fallback or error if no file is attached
159
+ state["response"] = "No valid Python file provided for execution."
160
+ return state
 
 
 
 
 
 
 
 
 
161
 
162
  try:
163
+ result = code_interpreter(code) # Your interpreter logic here
164
+ state["response"] = f"Python execution result:\n{result}"
165
  except Exception as e:
166
  state["response"] = f"Error executing Python code: {str(e)}"
167
 
 
170
 
171
 
172
 
 
 
 
 
173
  def run_and_submit_all( profile: gr.OAuthProfile | None):
174
  """
175
  Fetches all questions, runs the BasicAgent on them, submits all answers,