alonsosilva commited on
Commit
45adcef
1 Parent(s): ef1c8ea
01-ipywidgets-interactive-plots.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import solara
2
+ import ipywidgets as widgets
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+
6
+ @solara.component
7
+ def PlotLeft(alpha, beta, color1, color2):
8
+ fig = plt.figure(figsize=(4, 5))
9
+ xlim, ylim = [-np.pi, np.pi], [-1, 1]
10
+ x = np.linspace(*xlim)
11
+ plt.plot(x, beta*np.sin(x * alpha), label=r'$\beta\sin(\alpha x)$', color=color1)
12
+ plt.plot(x, (1-beta)*np.cos(2*alpha*x), label=r'$(1-\beta)\cos(2\alpha x)$', color=color2)
13
+ plt.xlabel('$x$')
14
+ plt.xlim(xlim)
15
+ plt.ylim(ylim)
16
+ plt.legend()
17
+ plt.show()
18
+
19
+ @solara.component
20
+ def PlotRight(alpha):
21
+ fig = plt.figure(figsize=(4, 5))
22
+ xlim, ylim = [-np.pi, np.pi], [0, 10]
23
+ x = np.linspace(*xlim)
24
+ plt.plot(x, np.exp(x * alpha), label=r'$e^{\alpha x}$')
25
+ plt.xlabel('$x$')
26
+ plt.xlim(xlim)
27
+ plt.ylim(ylim)
28
+ plt.legend()
29
+ plt.show()
30
+
31
+ alpha = solara.reactive(1.0)
32
+ beta = solara.reactive(.5)
33
+ color1 = solara.reactive('blue')
34
+ color2 = solara.reactive('red')
35
+ @solara.component
36
+ def Page():
37
+ #solara.Markdown("#Hello World", style="margin:auto;")
38
+ with solara.Column(style="padding:50px;"):
39
+ with solara.Row():
40
+ PlotLeft(alpha.value, beta.value, color1.value, color2.value)
41
+ with solara.Column(style="padding:50px"):
42
+ solara.Markdown("Parameters")
43
+ widgets.FloatSlider.element(min=0, max=2, value=alpha.value, on_value=alpha.set, description='$\\alpha$')
44
+ widgets.FloatSlider.element(min=0, max=1, value=beta.value, on_value=beta.set, continuous_update=False, description='$\\beta$')
45
+ solara.Markdown("Colors")
46
+ widgets.Dropdown.element(options=['blue', 'green', 'red'], value=color1.value, on_value=color1.set,
47
+ description=r'$\beta\sin(\alpha x)$')
48
+ widgets.Dropdown.element(options=['red', 'yellow', 'orange'], value=color2.value, on_value=color2.set,
49
+ description=r'$(1-\beta)\cos(2\alpha x)$',
50
+ style={'description_width': 'initial'})
51
+ PlotRight(alpha.value)
02-solara-interactive-plots.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import solara
2
+ import ipywidgets as widgets
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+
6
+ @solara.component
7
+ def PlotLeft(alpha, beta, color1, color2):
8
+ print("left")
9
+ fig = plt.figure(figsize=(4, 5))
10
+ xlim, ylim = [-np.pi, np.pi], [-1, 1]
11
+ x = np.linspace(*xlim)
12
+ plt.plot(x, beta*np.sin(x * alpha), label=r'$\beta\sin(\alpha x)$', color=color1)
13
+ plt.plot(x, (1-beta)*np.cos(2*alpha*x), label=r'$(1-\beta)\cos(2\alpha x)$', color=color2)
14
+ plt.xlabel('$x$')
15
+ plt.xlim(xlim)
16
+ plt.ylim(ylim)
17
+ plt.legend()
18
+ plt.show()
19
+
20
+ @solara.component
21
+ def PlotRight(alpha):
22
+ print("right")
23
+ fig = plt.figure(figsize=(4, 5))
24
+ xlim, ylim = [-np.pi, np.pi], [0, 10]
25
+ x = np.linspace(*xlim)
26
+ plt.plot(x, np.exp(x * alpha), label=r'$e^{\alpha x}$')
27
+ plt.xlabel('$x$')
28
+ plt.xlim(xlim)
29
+ plt.ylim(ylim)
30
+ plt.legend()
31
+ plt.show()
32
+
33
+ alpha = solara.reactive(1.0)
34
+ beta = solara.reactive(.5)
35
+ color1 = solara.reactive('blue')
36
+ color2 = solara.reactive('red')
37
+ @solara.component
38
+ def Page():
39
+ #solara.Markdown("#Hello World", style="margin:auto;")
40
+ with solara.Column(style="padding:50px;"):
41
+ with solara.Row():
42
+ PlotLeft(alpha.value, beta.value, color1.value, color2.value)
43
+ with solara.Column(style="padding:50px"):
44
+ solara.Text("Parameters")
45
+ solara.SliderFloat(r"$\alpha$", value=alpha, min=0, max=2)
46
+ #widgets.FloatSlider.element(min=0, max=2, value=alpha.value, on_value=alpha.set, description='$\\alpha$')
47
+ solara.SliderFloat(r"$\beta$", value=beta, min=0, max=1)
48
+ #widgets.FloatSlider.element(min=0, max=1, value=beta.value, on_value=beta.set, continuous_update=False, description='$\\beta$')
49
+ solara.Text("Colors")
50
+ solara.Select(label=r'$\beta\sin(\alpha x)$', value=color1, values=['blue', 'green', 'red'])
51
+ #widgets.Dropdown.element(options=['blue', 'green', 'red'], value=color1.value, on_value=color1.set,
52
+ # description=r'$\beta\sin(\alpha x)$')
53
+ solara.Select(label=r'$(1-\beta)\cos(2\alpha x)$', value=color2, values=['red', 'yellow', 'orange'])
54
+ #widgets.Dropdown.element(options=['red', 'yellow', 'orange'], value=color2.value, on_value=color2.set,
55
+ # description=r'$(1-\beta)\cos(2\alpha x)$',
56
+ # style={'description_width': 'initial'})
57
+ PlotRight(alpha.value)
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11
2
+
3
+ # Set up a new user named "user" with user ID 1000
4
+ RUN useradd -m -u 1000 user
5
+
6
+ # Switch to the "user" user
7
+ USER user
8
+
9
+ # Set home to the user's home directory
10
+ ENV HOME=/home/user \
11
+ PATH=/home/user/.local/bin:$PATH
12
+
13
+ # Set the working directory to the user's home directory
14
+ WORKDIR $HOME/app
15
+
16
+ # Try and run pip command after setting the user with `USER user` to avoid permission issues with Python
17
+ RUN pip install --no-cache-dir --upgrade pip
18
+
19
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
20
+ COPY --chown=user . $HOME/app
21
+
22
+ COPY --chown=user requirements.txt .
23
+
24
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
25
+
26
+ RUN mkdir $HOME/app/multipage
27
+
28
+ COPY --chown=user 01-ipywidgets-interactive-plots.py ./multipage
29
+
30
+ COPY --chown=user 02-solara-interactive-plots.py ./multipage
31
+
32
+ ENTRYPOINT ["solara", "run", "./multipage", "--host=0.0.0.0", "--port", "7860"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Alonso Silva Allende
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -6,6 +6,7 @@ colorTo: purple
6
  sdk: docker
7
  pinned: false
8
  license: mit
 
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
6
  sdk: docker
7
  pinned: false
8
  license: mit
9
+ app_port: 7860
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ anywidget==0.9.9
2
+ solara==1.31.0
3
+ numpy==1.26.4
4
+ matplotlib==3.8.4