Spaces:
Running
Running
Merge pull request #63 from marimo-team/ms/gallery
Browse files- .github/workflows/hf_sync.yml +19 -0
- Dockerfile +13 -0
- _server/README.md +21 -0
- _server/main.py +90 -0
.github/workflows/hf_sync.yml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to Hugging Face hub
|
| 2 |
+
on:
|
| 3 |
+
push:
|
| 4 |
+
branches: [main]
|
| 5 |
+
|
| 6 |
+
# to run this workflow manually from the Actions tab
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
sync-to-hub:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v4
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
- name: Push to hub
|
| 17 |
+
env:
|
| 18 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 19 |
+
run: git push https://mylessss:[email protected]/spaces/marimo-team/marimo-learn main
|
Dockerfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
|
| 2 |
+
|
| 3 |
+
COPY _server/main.py _server/main.py
|
| 4 |
+
COPY polars/ polars/
|
| 5 |
+
COPY duckdb/ duckdb/
|
| 6 |
+
|
| 7 |
+
RUN uv venv
|
| 8 |
+
RUN uv export --script _server/main.py | uv pip install -r -
|
| 9 |
+
|
| 10 |
+
ENV PORT=7860
|
| 11 |
+
EXPOSE 7860
|
| 12 |
+
|
| 13 |
+
CMD ["uv", "run", "_server/main.py"]
|
_server/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# marimo learn server
|
| 2 |
+
|
| 3 |
+
This folder contains server code for hosting marimo apps.
|
| 4 |
+
|
| 5 |
+
## Running the server
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
uv run --no-project main.py
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
## Building a Docker image
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
docker build -t marimo-learn .
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
## Running the Docker container
|
| 18 |
+
|
| 19 |
+
```bash
|
| 20 |
+
docker run -p 7860:7860 marimo-learn
|
| 21 |
+
```
|
_server/main.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# requires-python = ">=3.12"
|
| 3 |
+
# dependencies = [
|
| 4 |
+
# "fastapi",
|
| 5 |
+
# "marimo",
|
| 6 |
+
# "starlette",
|
| 7 |
+
# "python-dotenv",
|
| 8 |
+
# "pydantic",
|
| 9 |
+
# "duckdb",
|
| 10 |
+
# "altair==5.5.0",
|
| 11 |
+
# "beautifulsoup4==4.13.3",
|
| 12 |
+
# "httpx==0.28.1",
|
| 13 |
+
# "marimo",
|
| 14 |
+
# "nest-asyncio==1.6.0",
|
| 15 |
+
# "numba==0.61.0",
|
| 16 |
+
# "numpy==2.1.3",
|
| 17 |
+
# "polars==1.24.0",
|
| 18 |
+
# ]
|
| 19 |
+
# ///
|
| 20 |
+
|
| 21 |
+
import logging
|
| 22 |
+
import os
|
| 23 |
+
from pathlib import Path
|
| 24 |
+
|
| 25 |
+
import marimo
|
| 26 |
+
from dotenv import load_dotenv
|
| 27 |
+
from fastapi import FastAPI, Request
|
| 28 |
+
from fastapi.responses import HTMLResponse
|
| 29 |
+
|
| 30 |
+
# Load environment variables
|
| 31 |
+
load_dotenv()
|
| 32 |
+
|
| 33 |
+
# Set up logging
|
| 34 |
+
logging.basicConfig(level=logging.INFO)
|
| 35 |
+
logger = logging.getLogger(__name__)
|
| 36 |
+
|
| 37 |
+
# Get port from environment variable or use default
|
| 38 |
+
PORT = int(os.environ.get("PORT", 7860))
|
| 39 |
+
|
| 40 |
+
root_dir = Path(__file__).parent.parent
|
| 41 |
+
|
| 42 |
+
ROOTS = [
|
| 43 |
+
root_dir / "polars",
|
| 44 |
+
root_dir / "duckdb",
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
server = marimo.create_asgi_app(include_code=True)
|
| 49 |
+
app_names: list[str] = []
|
| 50 |
+
|
| 51 |
+
for root in ROOTS:
|
| 52 |
+
for filename in root.iterdir():
|
| 53 |
+
if filename.is_file() and filename.suffix == ".py":
|
| 54 |
+
app_path = root.stem + "/" + filename.stem
|
| 55 |
+
server = server.with_app(path=f"/{app_path}", root=str(filename))
|
| 56 |
+
app_names.append(app_path)
|
| 57 |
+
|
| 58 |
+
# Create a FastAPI app
|
| 59 |
+
app = FastAPI()
|
| 60 |
+
|
| 61 |
+
logger.info(f"Mounting {len(app_names)} apps")
|
| 62 |
+
for app_name in app_names:
|
| 63 |
+
logger.info(f" /{app_name}")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@app.get("/")
|
| 67 |
+
async def home(request: Request):
|
| 68 |
+
html_content = """
|
| 69 |
+
<!DOCTYPE html>
|
| 70 |
+
<html>
|
| 71 |
+
<head>
|
| 72 |
+
<title>marimo learn</title>
|
| 73 |
+
</head>
|
| 74 |
+
<body>
|
| 75 |
+
<h1>Welcome to marimo learn!</h1>
|
| 76 |
+
<p>This is a collection of interactive tutorials for learning data science libraries with marimo.</p>
|
| 77 |
+
<p>Check out the <a href="https://github.com/marimo-team/learn">GitHub repository</a> for more information.</p>
|
| 78 |
+
</body>
|
| 79 |
+
</html>
|
| 80 |
+
"""
|
| 81 |
+
return HTMLResponse(content=html_content)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
app.mount("/", server.build())
|
| 85 |
+
|
| 86 |
+
# Run the server
|
| 87 |
+
if __name__ == "__main__":
|
| 88 |
+
import uvicorn
|
| 89 |
+
|
| 90 |
+
uvicorn.run(app, host="0.0.0.0", port=PORT, log_level="info")
|