OuroborosM commited on
Commit
8a20586
·
1 Parent(s): 858f874

update code runner with indent removal

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -113,6 +113,7 @@ code_2 = """
113
 
114
  def Code_Runner(code_raw: str):
115
  # interpreter = CodeInterpreter(language="python", debug_mode=True)
 
116
  if '!pip' in code_raw:
117
  code_raw=code_raw.replace('!pip', 'pip')
118
  interpreter = CodeInterpreter(language="shell", debug_mode=True)
@@ -125,6 +126,19 @@ def Code_Runner(code_raw: str):
125
  print("Real Output: \n", output)
126
  return output
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  Code_Runner(code_1)
129
  Code_Runner(code_2)
130
 
 
113
 
114
  def Code_Runner(code_raw: str):
115
  # interpreter = CodeInterpreter(language="python", debug_mode=True)
116
+ code_raw = RemoveIndent(code_raw)
117
  if '!pip' in code_raw:
118
  code_raw=code_raw.replace('!pip', 'pip')
119
  interpreter = CodeInterpreter(language="shell", debug_mode=True)
 
126
  print("Real Output: \n", output)
127
  return output
128
 
129
+ def RemoveIndent(code_string, indentation_level=4):
130
+ lines = code_string.split('\n')
131
+ corrected_lines = []
132
+ for line in lines:
133
+ if line.strip() == "":
134
+ continue
135
+ line_without_indentation = line[indentation_level:] \
136
+ if line.startswith(' ' * indentation_level) else line
137
+ corrected_lines.append(line_without_indentation)
138
+ corrected_content = '\n'.join(corrected_lines)
139
+ return corrected_content
140
+
141
+
142
  Code_Runner(code_1)
143
  Code_Runner(code_2)
144