selim-ba commited on
Commit
ff5b28a
·
verified ·
1 Parent(s): 353d1dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -16
app.py CHANGED
@@ -145,16 +145,10 @@ class SuperSmartAgent:
145
  return state
146
 
147
  def execute_python_code(self, state):
148
- question = state["question"]
149
  file_name = state.get("file_name")
150
 
151
- # Case 1: Embedded code block
152
- code_blocks = re.findall(r"```(?:python)?(.*?)```", question, re.DOTALL)
153
- if code_blocks:
154
- code = textwrap.dedent(code_blocks[0]).strip()
155
- elif file_name and file_name.endswith(".py"):
156
- # Case 2: Load code from attached Python file
157
- file_path = os.path.join("data", file_name) # Make sure this path matches the actual mount
158
  try:
159
  with open(file_path, "r") as f:
160
  code = f.read()
@@ -162,14 +156,8 @@ class SuperSmartAgent:
162
  state["response"] = f"Error loading Python file: {e}"
163
  return state
164
  else:
165
- # Default fallback
166
- code = """
167
- def calculate():
168
- return 5
169
-
170
- result = calculate()
171
- print(result)
172
- """
173
 
174
  try:
175
  result = code_interpreter(code)
@@ -182,6 +170,7 @@ class SuperSmartAgent:
182
 
183
 
184
 
 
185
  def run_and_submit_all( profile: gr.OAuthProfile | None):
186
  """
187
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
145
  return state
146
 
147
  def execute_python_code(self, state):
 
148
  file_name = state.get("file_name")
149
 
150
+ if file_name and file_name.endswith(".py"):
151
+ file_path = os.path.join("data", file_name)
 
 
 
 
 
152
  try:
153
  with open(file_path, "r") as f:
154
  code = f.read()
 
156
  state["response"] = f"Error loading Python file: {e}"
157
  return state
158
  else:
159
+ state["response"] = "No valid Python file attached."
160
+ return state
 
 
 
 
 
 
161
 
162
  try:
163
  result = code_interpreter(code)
 
170
 
171
 
172
 
173
+
174
  def run_and_submit_all( profile: gr.OAuthProfile | None):
175
  """
176
  Fetches all questions, runs the BasicAgent on them, submits all answers,