Spaces:
Sleeping
Sleeping
alonsosilva
commited on
Commit
•
d037030
1
Parent(s):
0b44241
Add app
Browse files- Dockerfile +28 -0
- README.md +1 -0
- app.py +43 -0
- requirements.txt +2 -0
Dockerfile
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
COPY --chown=user app.py .
|
27 |
+
|
28 |
+
ENTRYPOINT ["solara", "run", "app.py", "--host=0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
@@ -6,6 +6,7 @@ colorTo: gray
|
|
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
|
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import solara
|
2 |
+
import anywidget
|
3 |
+
import traitlets
|
4 |
+
import ipywidgets as widgets
|
5 |
+
|
6 |
+
class CounterWidget(anywidget.AnyWidget):
|
7 |
+
_esm = """
|
8 |
+
import confetti from "https://esm.sh/[email protected]"
|
9 |
+
function render({ model, el }) {
|
10 |
+
let count = () => model.get("value");
|
11 |
+
let btn = document.createElement("button");
|
12 |
+
btn.innerHTML = `count is ${count()}`;
|
13 |
+
btn.classList.add("counter-btn");
|
14 |
+
btn.addEventListener("click", () => {
|
15 |
+
model.set("value", count() + 1);
|
16 |
+
model.save_changes();
|
17 |
+
});
|
18 |
+
model.on("change:value", () => {
|
19 |
+
btn.innerHTML = `count is ${count()}`;
|
20 |
+
confetti({ angle: (45*(count()-1)) });
|
21 |
+
});
|
22 |
+
el.appendChild(btn);
|
23 |
+
}
|
24 |
+
export default { render };
|
25 |
+
"""
|
26 |
+
_css = """
|
27 |
+
.counter-btn {
|
28 |
+
background:blue;
|
29 |
+
padding:10px 50px;
|
30 |
+
}
|
31 |
+
.counter-btn:hover {
|
32 |
+
background-color:green;
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
value = traitlets.Int(0).tag(sync=True)
|
36 |
+
|
37 |
+
@solara.component
|
38 |
+
def Page():
|
39 |
+
counter = CounterWidget()
|
40 |
+
with solara.Column(style={"padding":"30px"}):
|
41 |
+
solara.Markdown("#Anywidgets+Solara")
|
42 |
+
counter.element()
|
43 |
+
Page()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
anywidge==0.9.9
|
2 |
+
solara==1.32.0
|