Skip to content

Commit

Permalink
readme for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb committed Feb 10, 2025
1 parent e12ae07 commit 4504591
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 1,049 deletions.
23 changes: 23 additions & 0 deletions examples/streamlit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Streamlit demo
==============

Upload to Jamsocket:

```bash
npx jamsocket@latest service create my-streamlit-demo
npx jamsocket@latest service push my-streamlit-demo -f ./Dockerfile
```

Spawn an instance of the service:

```bash
npx jamsocket@latest spawn my-streamlit-demo
```

Open the "ready" URL in your browser.

Then, upload a streamlit app:

```bash
curl -X POST --data-binary @app.py https://<result of spawn>/_frag/upload/app.py
```
32 changes: 2 additions & 30 deletions examples/streamlit/app.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt

def mandelbrot(c, max_iter):
z = c
for n in range(max_iter):
if abs(z) > 2:
return n
z = z*z + c
return max_iter

def draw_mandelbrot(xmin,xmax,ymin,ymax,width,height,max_iter):
r1 = np.linspace(xmin, xmax, width)
r2 = np.linspace(ymin, ymax, height)
return (r1,r2,np.array([[mandelbrot(complex(r, i),max_iter) for r in r1] for i in r2]))

def main():
st.title('Mandelbrot Explorer')

# Set up the parameters
xmin = st.sidebar.slider('xmin', -2.0, 0.5, -2.0)
xmax = st.sidebar.slider('xmax', -2.0, 0.5, 0.5)
ymin = st.sidebar.slider('ymin', -1.5, 1.5, -1.5)
ymax = st.sidebar.slider('ymax', -1.5, 1.5, 1.5)
width = st.sidebar.slider('width', 100, 1000, 500)
height = st.sidebar.slider('height', 100, 1000, 500)
max_iter = st.sidebar.slider('max_iter', 1, 1000, 256)

# Draw the mandelbrot set
d = draw_mandelbrot(xmin,xmax,ymin,ymax,width,height,max_iter)
st.pyplot(plt.imshow(d[2], extent=(xmin, xmax, ymin, ymax)))
st.title('Hello World!')

if __name__ == "__main__":
main()
main()
86 changes: 0 additions & 86 deletions examples/streamlit/main.py

This file was deleted.

11 changes: 0 additions & 11 deletions examples/streamlit/pyproject.toml

This file was deleted.

1 change: 0 additions & 1 deletion examples/streamlit/requirements.txt

This file was deleted.

Loading

0 comments on commit 4504591

Please sign in to comment.