Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
from fasthtml.common import (
|
| 2 |
-
Main, Div, Form, Input, Code, Pre, fast_app, serve, picolink, MarkdownJS, HighlightJS
|
| 3 |
-
)
|
| 4 |
-
from fasthtml_hf import setup_hf_backup # to deploy to HF spaces
|
| 5 |
-
|
| 6 |
-
from code_runner import execute_code as execute
|
| 7 |
-
|
| 8 |
-
app, rt = fast_app(hdrs=[picolink, MarkdownJS(), HighlightJS()])
|
| 9 |
-
log = []
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
@app.get("/")
|
| 13 |
-
def pyconsole():
|
| 14 |
-
return Main(
|
| 15 |
-
Div(id="output"),
|
| 16 |
-
Form(
|
| 17 |
-
Input(name="code", placeholder=">>> Type Python code here (and hit enter)"),
|
| 18 |
-
hx_post="/run", hx_target="#output", hx_trigger="submit", id="input_form",
|
| 19 |
-
),
|
| 20 |
-
cls="container",
|
| 21 |
-
hx_swap="innerHTML show:window:bottom", # automatically scroll to the bottom of the page
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
@app.post("/run")
|
| 26 |
-
def run_code(data: dict):
|
| 27 |
-
log.append((data["code"], execute(data["code"])))
|
| 28 |
-
return Div(*[Div(Pre(Code(code, klass="python")), Div(output, cls="marked"), Div("---", cls="marked")) for code, output in log])
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
setup_hf_backup(app)
|
| 32 |
-
serve()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|