Spaces:
Runtime error
Runtime error
Commit
·
1ea45cf
1
Parent(s):
b42a9db
update code_runner
Browse files
app.py
CHANGED
|
@@ -103,20 +103,30 @@ class CodeBlock:
|
|
| 103 |
print(f"Output: {self.output}")
|
| 104 |
|
| 105 |
|
| 106 |
-
|
| 107 |
for i in range(3):
|
| 108 |
print("hello world")
|
| 109 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
def Code_Runner(code_raw: str, lang: str='python'):
|
| 111 |
# interpreter = CodeInterpreter(language="python", debug_mode=True)
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
code_block = CodeBlock(code_raw)
|
| 114 |
interpreter.active_block = code_block
|
| 115 |
output = interpreter.run()
|
| 116 |
print("Real Output: \n", output)
|
| 117 |
return output
|
| 118 |
|
| 119 |
-
Code_Runner(
|
|
|
|
| 120 |
|
| 121 |
async def TestCodeInterpret(CustomMessage:str):
|
| 122 |
# create a session
|
|
|
|
| 103 |
print(f"Output: {self.output}")
|
| 104 |
|
| 105 |
|
| 106 |
+
code_1 = """
|
| 107 |
for i in range(3):
|
| 108 |
print("hello world")
|
| 109 |
"""
|
| 110 |
+
code_2 = """
|
| 111 |
+
!pip install python-pptx
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
def Code_Runner(code_raw: str, lang: str='python'):
|
| 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)
|
| 119 |
+
else:
|
| 120 |
+
interpreter = CodeInterpreter(language="python", debug_mode=True)
|
| 121 |
+
# interpreter = CodeInterpreter(language=lang, debug_mode=True)
|
| 122 |
code_block = CodeBlock(code_raw)
|
| 123 |
interpreter.active_block = code_block
|
| 124 |
output = interpreter.run()
|
| 125 |
print("Real Output: \n", output)
|
| 126 |
return output
|
| 127 |
|
| 128 |
+
Code_Runner(code_1)
|
| 129 |
+
Code_Runner(code_2)
|
| 130 |
|
| 131 |
async def TestCodeInterpret(CustomMessage:str):
|
| 132 |
# create a session
|