Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: marimo learn HuggingFace gallery #63

Merged
merged 2 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/hf_sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Sync to Hugging Face hub
on:
push:
branches: [main]

# to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
sync-to-hub:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Push to hub
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: git push https://mylessss:[email protected]/spaces/marimo-team/marimo-learn main
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

COPY _server/main.py _server/main.py
COPY polars/ polars/
COPY duckdb/ duckdb/

RUN uv venv
RUN uv export --script _server/main.py | uv pip install -r -

ENV PORT=7860
EXPOSE 7860

CMD ["uv", "run", "_server/main.py"]
21 changes: 21 additions & 0 deletions _server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# marimo learn server

This folder contains server code for hosting marimo apps.

## Running the server

```bash
uv run --no-project main.py
```

## Building a Docker image

```bash
docker build -t marimo-learn .
```

## Running the Docker container

```bash
docker run -p 7860:7860 marimo-learn
```
90 changes: 90 additions & 0 deletions _server/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "fastapi",
# "marimo",
# "starlette",
# "python-dotenv",
# "pydantic",
# "duckdb",
# "altair==5.5.0",
# "beautifulsoup4==4.13.3",
# "httpx==0.28.1",
# "marimo",
# "nest-asyncio==1.6.0",
# "numba==0.61.0",
# "numpy==2.1.3",
# "polars==1.24.0",
# ]
# ///

import logging
import os
from pathlib import Path

import marimo
from dotenv import load_dotenv
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse

# Load environment variables
load_dotenv()

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Get port from environment variable or use default
PORT = int(os.environ.get("PORT", 7860))

root_dir = Path(__file__).parent.parent

ROOTS = [
root_dir / "polars",
root_dir / "duckdb",
]


server = marimo.create_asgi_app(include_code=True)
app_names: list[str] = []

for root in ROOTS:
for filename in root.iterdir():
if filename.is_file() and filename.suffix == ".py":
app_path = root.stem + "/" + filename.stem
server = server.with_app(path=f"/{app_path}", root=str(filename))
app_names.append(app_path)

# Create a FastAPI app
app = FastAPI()

logger.info(f"Mounting {len(app_names)} apps")
for app_name in app_names:
logger.info(f" /{app_name}")


@app.get("/")
async def home(request: Request):
html_content = """
<!DOCTYPE html>
<html>
<head>
<title>marimo learn</title>
</head>
<body>
<h1>Welcome to marimo learn!</h1>
<p>This is a collection of interactive tutorials for learning data science libraries with marimo.</p>
<p>Check out the <a href="https://github.com/marimo-team/learn">GitHub repository</a> for more information.</p>
</body>
</html>
"""
return HTMLResponse(content=html_content)


app.mount("/", server.build())

# Run the server
if __name__ == "__main__":
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=PORT, log_level="info")