Download app.py from xcx0902/python: direct link, hf CLI and curl.
- Browser
- Download file 669 Bytes
-
https://huggingface.co/spaces/xcx0902/python/resolve/main/app.py
- Command line
-
hf download hf://spaces/xcx0902/python/app.py
-
curl -L -o app.py https://huggingface.co/spaces/xcx0902/python/resolve/main/app.py
669 Bytes
| import gradio as gr | |
| import io | |
| import sys | |
| import os | |
| class PersistentRunner: | |
| def __init__(self): | |
| self.globals = {} | |
| def run(self, code): | |
| old_stdout = sys.stdout | |
| sys.stdout = buffer = io.StringIO() | |
| try: | |
| exec(code, self.globals) | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| finally: | |
| sys.stdout = old_stdout | |
| return buffer.getvalue() | |
| runner = PersistentRunner() | |
| def run(code): | |
| if code.startswith("!"): | |
| os.system(code[1:]) | |
| else: | |
| return runner.run(code.replace("\\n", "\n")) | |
| demo = gr.Interface(fn=run, inputs="text", outputs="text") | |
| demo.launch() | |