diff --git a/interpreter/core/computer/display/display.py b/interpreter/core/computer/display/display.py index 84b00479f2..a57d3e34f1 100644 --- a/interpreter/core/computer/display/display.py +++ b/interpreter/core/computer/display/display.py @@ -37,6 +37,13 @@ def screenshot(self, show=True, quadrant=None): else: raise ValueError("Invalid quadrant. Choose between 1 and 4.") + # Shrink screenshot so it's no more than 1024 wide + screenshot_width, screenshot_height = screenshot.size + if screenshot_width > 1024: + ratio = 1024.0 / screenshot_width + new_height = int(screenshot_height * ratio) + screenshot = screenshot.resize((1024, new_height), Image.ANTIALIAS) + screenshot.save(temp_file.name) # Open the image file with PIL diff --git a/interpreter/core/computer/terminal/languages/jupyter_language.py b/interpreter/core/computer/terminal/languages/jupyter_language.py index 582fa710d4..e122b9bf0a 100644 --- a/interpreter/core/computer/terminal/languages/jupyter_language.py +++ b/interpreter/core/computer/terminal/languages/jupyter_language.py @@ -33,14 +33,22 @@ def __init__(self): # Give it our same matplotlib backend # backend = matplotlib.get_backend() + # DISABLED because we actually do want HTML output to work, other types of output too # Get backend which bubbles everything up as images - backend = "Agg" - - code_to_run = f""" - import matplotlib - matplotlib.use('{backend}') - """ - self.run(code_to_run) + # backend = "Agg" + # code = f""" + # import matplotlib + # matplotlib.use('{backend}') + # """ + # self.run(code) + + # DISABLED because it doesn't work?? + # Disable color outputs in the terminal, which don't look good in OI and aren't useful + # code = """ + # from IPython.core.getipython import get_ipython + # get_ipython().colors = 'NoColor' + # """ + # self.run(code) def terminate(self): self.kc.stop_channels() @@ -104,11 +112,15 @@ def iopub_message_listener(): {"type": "console", "format": "output", "content": line} ) elif msg["msg_type"] == "error": + content = "\n".join(content["traceback"]) + # Remove color codes + ansi_escape = re.compile(r"\x1B\[[0-?]*[ -/]*[@-~]") + content = ansi_escape.sub("", content) message_queue.put( { "type": "console", "format": "output", - "content": "\n".join(content["traceback"]), + "content": content, } ) elif msg["msg_type"] in ["display_data", "execute_result"]: diff --git a/interpreter/core/respond.py b/interpreter/core/respond.py index 4dfe77a5a7..c5e68cafeb 100644 --- a/interpreter/core/respond.py +++ b/interpreter/core/respond.py @@ -156,6 +156,15 @@ def respond(interpreter): # don't let it import computer on os mode — we handle that! if interpreter.os and language == "python": code = code.replace("import computer", "") + code = code.replace( + "from computer import keyboard", "keyboard = computer.keyboard" + ) + code = code.replace( + "from computer import mouse", "mouse = computer.mouse" + ) + code = code.replace( + "from computer import display", "mouse = computer.display" + ) # yield each line for line in interpreter.computer.run(language, code): diff --git a/interpreter/terminal_interface/start_terminal_interface.py b/interpreter/terminal_interface/start_terminal_interface.py index 289ae4d181..ea6feb7225 100644 --- a/interpreter/terminal_interface/start_terminal_interface.py +++ b/interpreter/terminal_interface/start_terminal_interface.py @@ -398,13 +398,12 @@ def start_terminal_interface(interpreter): # FOR TESTING ONLY # Install Open Interpreter from GitHub - print("INSTALLING OI FROM GITHUB") - for chunk in interpreter.computer.run( - "shell", - "pip install git+https://github.com/KillianLucas/open-interpreter.git", - ): - if chunk.get("format") != "active_line": - print(chunk.get("content")) + # for chunk in interpreter.computer.run( + # "shell", + # "pip install git+https://github.com/KillianLucas/open-interpreter.git", + # ): + # if chunk.get("format") != "active_line": + # print(chunk.get("content")) # Give it access to the computer via Python for _ in interpreter.computer.run(