Spaces:
Sleeping
Sleeping
| # /// script | |
| # requires-python = ">=3.10" | |
| # dependencies = ["marimo"] | |
| # /// | |
| import marimo | |
| __generated_with = "0.17.6" | |
| app = marimo.App() | |
| def _(): | |
| import marimo as mo | |
| import os | |
| WORKSPACE = os.environ.get("WORKSPACE", "/app/workspace") | |
| return WORKSPACE, mo, os | |
| def _(mo): | |
| mo.md("# π¦ Marimo Sandbox") | |
| mo.md("Toggle this panel from Agent Zero chat UI") | |
| mo.md("---") | |
| return | |
| def _(mo): | |
| """Code Editor Cell""" | |
| mo.md("### π» Code Editor") | |
| code_editor = mo.ui.code_editor( | |
| language="python", | |
| value="# Write your code here\nprint('Hello from Marimo Zero!')", | |
| label="" | |
| ) | |
| def run_code(code): | |
| import sys | |
| from io import StringIO | |
| old_stdout = sys.stdout | |
| sys.stdout = buf = StringIO() | |
| try: | |
| exec(code, {}, {}) | |
| output = buf.getvalue() | |
| if output: | |
| return mo.md(f"**Output:**\n```\n{output}\n```") | |
| else: | |
| return mo.md("β Code executed (no output)") | |
| except Exception as e: | |
| return mo.md(f"β Error:\n```\n{str(e)}\n```") | |
| finally: | |
| sys.stdout = old_stdout | |
| result = run_code(code_editor.value) | |
| mo.vstack([ | |
| code_editor, | |
| mo.ui.run_button(label="βΆοΈ Run"), | |
| result | |
| ]) | |
| return | |
| def _(mo, WORKSPACE, os): | |
| """File Browser Cell""" | |
| mo.md("### π Workspace Files") | |
| def list_files(): | |
| if not os.path.exists(WORKSPACE): | |
| return mo.md("β οΈ Workspace not found") | |
| files = os.listdir(WORKSPACE) | |
| if not files: | |
| return mo.md("π Empty workspace") | |
| file_list = "\n".join([f"- π `{f}`" for f in sorted(files)]) | |
| return mo.md(file_list) | |
| list_files() | |
| return | |
| def _(mo, WORKSPACE, os): | |
| """File Editor Cell""" | |
| mo.md("### βοΈ File Editor") | |
| filename = mo.ui.text( | |
| label="Filename:", | |
| value="example.md", | |
| full_width=False | |
| ) | |
| filepath = os.path.join(WORKSPACE, filename.value) | |
| def read_file(name): | |
| path = os.path.join(WORKSPACE, name) | |
| if os.path.exists(path): | |
| with open(path, 'r') as f: | |
| return f.read() | |
| return "# New file\n\nStart writing..." | |
| content = mo.ui.text_area( | |
| label="Content:", | |
| value=read_file(filename.value), | |
| full_width=True, | |
| height=300 | |
| ) | |
| def save_file(name, text): | |
| path = os.path.join(WORKSPACE, name) | |
| with open(path, 'w') as f: | |
| f.write(text) | |
| return mo.md(f"β Saved to `{path}`") | |
| mo.vstack([ | |
| filename, | |
| content, | |
| mo.ui.run_button(label="πΎ Save"), | |
| save_file(filename.value, content.value) | |
| ]) | |
| return | |
| def _(mo): | |
| """Terminal Output Cell""" | |
| mo.md("### π Output") | |
| mo.md(""" | |
| View execution results, plots, and outputs here. | |
| **Tip:** Use `print()` in code cells to see output here. | |
| """) | |
| return | |
| if __name__ == "__main__": | |
| app.run() | |