Spaces:
Runtime error
Runtime error
Commit
·
b42a9db
1
Parent(s):
0db1cb0
add code_runner
Browse files- app.py +29 -0
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -89,6 +89,35 @@ import torch
|
|
| 89 |
from codeinterpreterapi import CodeInterpreterSession
|
| 90 |
import html2text
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
async def TestCodeInterpret(CustomMessage:str):
|
| 93 |
# create a session
|
| 94 |
session = CodeInterpreterSession(llm=GPTfake)
|
|
|
|
| 89 |
from codeinterpreterapi import CodeInterpreterSession
|
| 90 |
import html2text
|
| 91 |
|
| 92 |
+
from interpreter.code_interpreter import CodeInterpreter
|
| 93 |
+
from interpreter.code_block import CodeBlock
|
| 94 |
+
|
| 95 |
+
class CodeBlock:
|
| 96 |
+
def __init__(self, code):
|
| 97 |
+
self.code = code
|
| 98 |
+
self.output = ""
|
| 99 |
+
self.active_line = None
|
| 100 |
+
|
| 101 |
+
def refresh(self):
|
| 102 |
+
print(f"Active line: {self.active_line}")
|
| 103 |
+
print(f"Output: {self.output}")
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
code_raw = """
|
| 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 |
+
interpreter = CodeInterpreter(language=lang, debug_mode=True)
|
| 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(code_raw)
|
| 120 |
+
|
| 121 |
async def TestCodeInterpret(CustomMessage:str):
|
| 122 |
# create a session
|
| 123 |
session = CodeInterpreterSession(llm=GPTfake)
|
requirements.txt
CHANGED
|
@@ -25,3 +25,4 @@ scipy
|
|
| 25 |
codeinterpreterapi
|
| 26 |
jupyter-kernel-gateway
|
| 27 |
html2text
|
|
|
|
|
|
| 25 |
codeinterpreterapi
|
| 26 |
jupyter-kernel-gateway
|
| 27 |
html2text
|
| 28 |
+
open-interpreter
|