Spaces:
Sleeping
Sleeping
jrosell
commited on
Commit
·
3b53c8a
0
Parent(s):
first
Browse files- .gitattributes +35 -0
- .gitignore +3 -0
- Dockerfile +54 -0
- README.md +80 -0
- app.R +34 -0
- card3d.css +15 -0
- card3d.js +44 -0
- deploy_docker.sh +4 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.Renviron
|
2 |
+
*.sqlite
|
3 |
+
build.log
|
Dockerfile
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ARG GITHUB_PAT
|
2 |
+
|
3 |
+
FROM rocker/r2u:22.04
|
4 |
+
|
5 |
+
ENV RUSTUP_HOME=/usr/local/rustup \
|
6 |
+
CARGO_HOME=/usr/local/cargo \
|
7 |
+
PATH=/usr/local/cargo/bin:$PATH
|
8 |
+
|
9 |
+
# Install system packages
|
10 |
+
RUN set -eux; \
|
11 |
+
apt-get update; \
|
12 |
+
apt-get install -y --no-install-recommends \
|
13 |
+
git \
|
14 |
+
sudo \
|
15 |
+
sqlite3 \
|
16 |
+
ca-certificates \
|
17 |
+
gcc \
|
18 |
+
libc6-dev \
|
19 |
+
wget \
|
20 |
+
&& sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers \
|
21 |
+
&& sed -i -e '/^suppressMessages(bspm::enable())$/i options(bspm.sudo=TRUE)' /etc/R/Rprofile.site \
|
22 |
+
; \
|
23 |
+
\
|
24 |
+
url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
|
25 |
+
wget "$url"; \
|
26 |
+
chmod +x rustup-init; \
|
27 |
+
./rustup-init -y --no-modify-path --default-toolchain beta --default-host x86_64-unknown-linux-gnu; \
|
28 |
+
rm rustup-init; \
|
29 |
+
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
|
30 |
+
rustup --version; \
|
31 |
+
cargo --version; \
|
32 |
+
rustc --version; \
|
33 |
+
\
|
34 |
+
apt-get remove -y --auto-remove \
|
35 |
+
wget \
|
36 |
+
; \
|
37 |
+
rm -rf /var/lib/apt/lists/*;
|
38 |
+
|
39 |
+
# Install R packages
|
40 |
+
RUN install2.r --error -s --deps TRUE htmltools tibble dplyr purrr rlang glue this.path DBI pool RSQLite remotes promises assertthat log here zeallot dbplyr stringr tidyverse
|
41 |
+
RUN Rscript -e "install.packages('b64', repos = c('https://extendr.r-universe.dev', getOption('repos')))"
|
42 |
+
RUN Rscript -e "install.packages('uwu', repos = c('https://josiahparry.r-universe.dev', getOption('repos')))"
|
43 |
+
RUN --mount=type=secret,id=GITHUB_PAT GITHUB_PAT=$(cat /run/secrets/GITHUB_PAT) \
|
44 |
+
installGithub.r jrosell/ambhtmx devOpifex/ambiorix devOpifex/scilis devOpifex/signaculum
|
45 |
+
|
46 |
+
# Prepare the user
|
47 |
+
ENV HOME=/workspace \
|
48 |
+
PATH=/workspace/.local/bin:$PATH
|
49 |
+
WORKDIR /workspace
|
50 |
+
COPY . .
|
51 |
+
|
52 |
+
# Entry
|
53 |
+
EXPOSE 7860
|
54 |
+
CMD R -e "print(nchar(Sys.getenv('GITHUB_PAT'))); source('app.R'); "
|
README.md
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: ambhtmx.card3d
|
3 |
+
emoji: 🏃
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: pink
|
6 |
+
sdk: docker
|
7 |
+
pinned: false
|
8 |
+
---
|
9 |
+
|
10 |
+
<!-- badges: start -->
|
11 |
+
|
12 |
+
[![Lifecycle:
|
13 |
+
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
|
14 |
+
|
15 |
+
<!-- badges: end -->
|
16 |
+
|
17 |
+
**THIS IS A WORK IN PROGRESS, DO NOT USE**
|
18 |
+
|
19 |
+
## Deployment options
|
20 |
+
|
21 |
+
### Hugging Face Spaces
|
22 |
+
|
23 |
+
When you push a repository to a Hugging Face Spaces with the option to deploy Dockerfile and include a Dockerfile, Hugging Face will start building and running your app in the Space.
|
24 |
+
|
25 |
+
Try the demo here:
|
26 |
+
|
27 |
+
* Direct URL to the deployed app: https://jrosell-ambhtmx-crud.hf.space/
|
28 |
+
* Space URL: https://huggingface.co/spaces/jrosell/ambhtmx.card3d
|
29 |
+
|
30 |
+
|
31 |
+
### Runing the example in Docker
|
32 |
+
|
33 |
+
All in one:
|
34 |
+
|
35 |
+
```
|
36 |
+
bash deploy_docker.sh
|
37 |
+
```
|
38 |
+
|
39 |
+
Step by step:
|
40 |
+
|
41 |
+
1. Building the ambhtmx-image:
|
42 |
+
|
43 |
+
```
|
44 |
+
docker build -f Dockerfile -t ambhtmx-card3d-image . &&
|
45 |
+
docker run -p 7860:7860 --name ambhtmx-card3d-container --rm ambhtmx-card3d-image
|
46 |
+
```
|
47 |
+
|
48 |
+
2. Check the app on http://127.0.0.1:3000
|
49 |
+
|
50 |
+
4. Stoping and removing the ambhtmx-card3d-container:
|
51 |
+
|
52 |
+
```
|
53 |
+
docker container rm -f ambhtmx-card3d-container
|
54 |
+
```
|
55 |
+
|
56 |
+
5. Removing the image
|
57 |
+
```
|
58 |
+
docker images 'ambhtmx-card3d-image' -a -q
|
59 |
+
docker rmi ID
|
60 |
+
|
61 |
+
## Troubleshooting
|
62 |
+
|
63 |
+
If you want to see the logs:
|
64 |
+
|
65 |
+
```
|
66 |
+
docker build -f Dockerfile --no-cache --progress=plain -t ambhtmx-card3d-image . 2>&1 | tee build.log
|
67 |
+
```
|
68 |
+
|
69 |
+
Check the [known issues](https://github.com/jrosell/ambhtmx/issues), and if you have another issue? Please, [let me know](https://github.com/jrosell/ambhtmx/issues).
|
70 |
+
|
71 |
+
|
72 |
+
git init
|
73 |
+
git add -A
|
74 |
+
git branch -M main
|
75 |
+
git remote add origin [email protected]:jrosell/ambhtx.card3d.git
|
76 |
+
git remote add hg [email protected]:spaces/jrosell/ambhtmx.card3d
|
77 |
+
git remote -v
|
78 |
+
git remote set-url --add --push origin [email protected]:jrosell/ambhtmx.card3d.git
|
79 |
+
git remote set-url --add --push origin [email protected]:spaces/jrosell/ambhtmx.card3d
|
80 |
+
git push -u origin main
|
app.R
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# remotes::install_github("jrosell/ambhtmx", force = TRUE)
|
2 |
+
library(ambhtmx)
|
3 |
+
# devtools::load_all()
|
4 |
+
|
5 |
+
card_3d_demo <- \() {
|
6 |
+
card <- "card"
|
7 |
+
tryCatch(
|
8 |
+
expr = {
|
9 |
+
# Original python code credit: https://fastht.ml/
|
10 |
+
# Design credit: https://codepen.io/markmiro/pen/wbqMPa
|
11 |
+
bgurl <- "https://ucarecdn.com/35a0e8a7-fcc5-48af-8a3f-70bb96ff5c48/-/preview/750x1000/"
|
12 |
+
card_styles <- "font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif; perspective: 1500px;"
|
13 |
+
card_3d <- \(text, bgurl, amt, left_align) {
|
14 |
+
align <- ifelse(left_align, 'left', 'right')
|
15 |
+
scr <- script_from_js_tpl('card3d.js', amt = amt)
|
16 |
+
sty <- style_from_css_tpl(
|
17 |
+
'card3d.css', bgurl = glue('url({bgurl})'), align = align
|
18 |
+
)
|
19 |
+
div(text, div(), scr, sty, align = align)
|
20 |
+
}
|
21 |
+
card <- card_3d("Mouseover me", bgurl, amt = 1.5, left_align = T)
|
22 |
+
},
|
23 |
+
error = \(e) print(e)
|
24 |
+
)
|
25 |
+
div(card, style = card_styles)
|
26 |
+
}
|
27 |
+
|
28 |
+
app <- ambhtmx_app(host = "0.0.0.0", port = "3000", protocol ="http")$app
|
29 |
+
|
30 |
+
app$get("/", \(req, res) {
|
31 |
+
card_3d_demo() |> send_page(res)
|
32 |
+
})
|
33 |
+
|
34 |
+
app$start()
|
card3d.css
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
me {
|
2 |
+
position: relative; width: 225px; height: 300px; padding: 1em; display: flex;
|
3 |
+
flex-direction: column; justify-content: flex-end;
|
4 |
+
font-weight: bold; text-align: var(--tpl-align); text-shadow: 0 0 4px #000; color: #ddd;
|
5 |
+
-webkit-text-stroke: 1px black; margin: 1em; font-size: 1.25em;
|
6 |
+
box-shadow: 0 1px 5px #00000099; border-radius: 10px; background: var(--tpl-bgurl) center/cover;
|
7 |
+
transition: .3s ease-out; transition-property: transform, box-shadow;
|
8 |
+
touch-action: none; /* Prevents scrolling on touch devices */
|
9 |
+
}
|
10 |
+
me:hover { transition-duration: .15s; box-shadow: 0 5px 20px 5px #00000044; }
|
11 |
+
me > div {
|
12 |
+
position: absolute; inset: 0; border-radius: 10px;
|
13 |
+
background-image: radial-gradient(circle at 90% -20%, #ffffff55, #0000000f);
|
14 |
+
pointer-events: none; /* Allows touch events to pass through */
|
15 |
+
}
|
card3d.js
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
me().on('mouseenter', ev => {
|
2 |
+
let e = me(ev)
|
3 |
+
e.bounds = e.getBoundingClientRect()
|
4 |
+
e.on('mousemove', e.rotateToPointer)
|
5 |
+
}).on('mouseleave', ev => {
|
6 |
+
let e = me(ev)
|
7 |
+
e.off('mousemove', e.rotateToPointer)
|
8 |
+
e.style.transform = e.style.background = ''
|
9 |
+
})
|
10 |
+
|
11 |
+
// Use a separate function for touch events to allow passive listener
|
12 |
+
function handleTouchStart(ev) {
|
13 |
+
let e = me(ev)
|
14 |
+
e.bounds = e.getBoundingClientRect()
|
15 |
+
e.addEventListener('touchmove', e.rotateToPointer, { passive: true })
|
16 |
+
e.addEventListener('touchend', handleTouchEnd, { passive: true })
|
17 |
+
}
|
18 |
+
|
19 |
+
function handleTouchEnd(ev) {
|
20 |
+
let e = me(ev.target)
|
21 |
+
e.removeEventListener('touchmove', e.rotateToPointer)
|
22 |
+
e.removeEventListener('touchend', handleTouchEnd)
|
23 |
+
e.style.transform = e.style.background = ''
|
24 |
+
}
|
25 |
+
|
26 |
+
me().addEventListener('touchstart', handleTouchStart, { passive: true })
|
27 |
+
|
28 |
+
me().rotateToPointer = ev => {
|
29 |
+
let e = me(ev.target), b = e.bounds
|
30 |
+
let x, y
|
31 |
+
if (ev.type === 'touchmove') {
|
32 |
+
x = ev.touches[0].clientX - b.x - b.width / 2
|
33 |
+
y = ev.touches[0].clientY - b.y - b.height / 2
|
34 |
+
} else {
|
35 |
+
x = ev.clientX - b.x - b.width / 2
|
36 |
+
y = ev.clientY - b.y - b.height / 2
|
37 |
+
}
|
38 |
+
let d = Math.hypot(x,y)
|
39 |
+
let amt = {amt}
|
40 |
+
e.style.transform = `scale3d(${ 1 + 0.07 * amt }, ${ 1 + 0.07 * amt }, 1.0)
|
41 |
+
rotate3d(${ y/100*amt }, ${ -x/100*amt }, 0, ${ Math.log(d)*2*amt }deg)`
|
42 |
+
me('div', e).style.backgroundImage = `radial-gradient(
|
43 |
+
circle at ${ x*2 + b.width/2 }px ${ y*2 + b.height/2 }px, #ffffff77, #0000000f)`
|
44 |
+
}
|
deploy_docker.sh
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(docker container rm -f ambhtmx-card3d-container || true)\
|
2 |
+
&& (docker rmi $(docker images --format '{{.Repository}}:{{.ID}}'| egrep 'ambhtmx-card3d' | cut -d':' -f2 | uniq) --force || true) \
|
3 |
+
&& docker build -f Dockerfile -t ambhtmx-card3d-image . \
|
4 |
+
&& docker run --env-file=.Renviron -p 7860:7860 --name ambhtmx-card3d-container --rm ambhtmx-card3d-image
|