Spaces:
Sleeping
Sleeping
Commit
·
5b080ef
0
Parent(s):
My changes
Browse files- .gitattributes +35 -0
- .gitignore +3 -0
- Dockerfile +73 -0
- README.md +68 -0
- app.R +161 -0
- deploy_hf.sh +4 -0
- docker_rm.sh +2 -0
- docker_run.sh +2 -0
- last_depoy.txt +1 -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,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
make \
|
17 |
+
libcurl4-openssl-dev \
|
18 |
+
libssl-dev \
|
19 |
+
libxml2-dev \
|
20 |
+
zlib1g-dev \
|
21 |
+
libfontconfig1-dev \
|
22 |
+
libfreetype6-dev \
|
23 |
+
libpng-dev \
|
24 |
+
libtiff5-dev \
|
25 |
+
libjpeg-dev \
|
26 |
+
libharfbuzz-dev \
|
27 |
+
libfribidi-dev \
|
28 |
+
libpq-dev \
|
29 |
+
libgit2-dev \
|
30 |
+
gdal-bin libgdal-dev \
|
31 |
+
libudunits2-dev \
|
32 |
+
pandoc \
|
33 |
+
ca-certificates \
|
34 |
+
gcc \
|
35 |
+
libc6-dev \
|
36 |
+
wget \
|
37 |
+
&& sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers \
|
38 |
+
&& sed -i -e '/^suppressMessages(bspm::enable())$/i options(bspm.sudo=TRUE)' /etc/R/Rprofile.site \
|
39 |
+
; \
|
40 |
+
\
|
41 |
+
url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
|
42 |
+
wget "$url"; \
|
43 |
+
chmod +x rustup-init; \
|
44 |
+
./rustup-init -y --no-modify-path --default-toolchain beta --default-host x86_64-unknown-linux-gnu; \
|
45 |
+
rm rustup-init; \
|
46 |
+
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
|
47 |
+
rustup --version; \
|
48 |
+
cargo --version; \
|
49 |
+
rustc --version; \
|
50 |
+
\
|
51 |
+
apt-get remove -y --auto-remove \
|
52 |
+
wget \
|
53 |
+
; \
|
54 |
+
rm -rf /var/lib/apt/lists/*;
|
55 |
+
|
56 |
+
# Install R packages
|
57 |
+
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 rmarkdown plotly
|
58 |
+
RUN Rscript -e "install.packages('b64', repos = c('https://extendr.r-universe.dev', getOption('repos')))"
|
59 |
+
RUN Rscript -e "install.packages('uwu', repos = c('https://josiahparry.r-universe.dev', getOption('repos')))"
|
60 |
+
RUN --mount=type=secret,id=GITHUB_PAT GITHUB_PAT=$(cat /run/secrets/GITHUB_PAT) \
|
61 |
+
installGithub.r devOpifex/ambiorix devOpifex/scilis devOpifex/signaculum
|
62 |
+
RUN --mount=type=secret,id=GITHUB_PAT GITHUB_PAT=$(cat /run/secrets/GITHUB_PAT) \
|
63 |
+
installGithub.r jrosell/ambhtmx
|
64 |
+
|
65 |
+
# Prepare the user
|
66 |
+
ENV HOME=/workspace \
|
67 |
+
PATH=/workspace/.local/bin:$PATH
|
68 |
+
WORKDIR /workspace
|
69 |
+
COPY . .
|
70 |
+
|
71 |
+
# Entry
|
72 |
+
EXPOSE 7860
|
73 |
+
CMD R -e "print(nchar(Sys.getenv('GITHUB_PAT'))); source('app.R'); "
|
README.md
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: ambhtmx.tonejs
|
3 |
+
emoji: 🏃
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: pink
|
6 |
+
sdk: docker
|
7 |
+
pinned: false
|
8 |
+
---
|
9 |
+
|
10 |
+
<!-- badges: start -->
|
11 |
+
|
12 |
+
[](https://www.tidyverse.org/lifecycle/#experimental)
|
14 |
+
|
15 |
+
<!-- badges: end -->
|
16 |
+
|
17 |
+
**THIS IS A WORK IN PROGRESS, DO NOT USE**
|
18 |
+
|
19 |
+
See the demo here:
|
20 |
+
|
21 |
+
* Direct URL to the deployed app: https://jrosell-ambhtmx-tonejs.hf.space/
|
22 |
+
* Space URL: https://huggingface.co/spaces/jrosell/ambhtmx.tonejs
|
23 |
+
|
24 |
+
Or test it locally:
|
25 |
+
|
26 |
+
```
|
27 |
+
git clone [email protected]:jrosell/ambhtmx.tonejs.git
|
28 |
+
cd ambhtmx.tonejs
|
29 |
+
echo GITHUB_PAT="Your token from github" >> .Renviron
|
30 |
+
bash docker_run.sh
|
31 |
+
```
|
32 |
+
|
33 |
+
If you want, you can remove docker containers and images:
|
34 |
+
```
|
35 |
+
bash docker_rm.sh
|
36 |
+
```
|
37 |
+
|
38 |
+
## How to use Github and Hugging Face Spaces for my project
|
39 |
+
|
40 |
+
When you pushing 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.
|
41 |
+
|
42 |
+
Customize this example, to enable Hugging Face Spaces as additional remote:
|
43 |
+
|
44 |
+
```
|
45 |
+
git init
|
46 |
+
git add -A
|
47 |
+
git status
|
48 |
+
git commit -m "My changes"
|
49 |
+
git remote add origin [email protected]:jrosell/ambhtmx.tonejs.git
|
50 |
+
git remote add gh [email protected]:jrosell/ambhtmx.tonejs.git
|
51 |
+
git remote add hf [email protected]:spaces/jrosell/ambhtmx.tonejs
|
52 |
+
git remote -v
|
53 |
+
```
|
54 |
+
|
55 |
+
Then, to depoly to Hugging Face Spaces run:
|
56 |
+
|
57 |
+
```
|
58 |
+
bash deploy_hf.sh
|
59 |
+
```
|
60 |
+
|
61 |
+
## Troubleshooting
|
62 |
+
|
63 |
+
Kown issues:
|
64 |
+
|
65 |
+
* Only updates when refreshing the whole page. WIP should rerender on innerHTML replace.
|
66 |
+
|
67 |
+
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).
|
68 |
+
|
app.R
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# remotes::install_github("jrosell/ambhtmx", force = TRUE)
|
2 |
+
library(ambhtmx)
|
3 |
+
|
4 |
+
page_title <- "ambhtmx tonejs example"
|
5 |
+
|
6 |
+
head_tags <- htmltools::tagList(
|
7 |
+
tags$link(href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css", rel = "stylesheet", integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH", crossorigin="anonymous"),
|
8 |
+
tags$script(src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js", integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz", crossorigin="anonymous"),
|
9 |
+
htmltools::HTML('<script src="https://cdn.jsdelivr.net/gh/gnat/surreal@main/surreal.js"></script><script src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script>'),
|
10 |
+
htmltools::HTML('<script src="http://unpkg.com/tone"></script>'),
|
11 |
+
htmltools::HTML('<style>input[type="radio"] {margin: 0 5px 0 20px}</style>')
|
12 |
+
)
|
13 |
+
|
14 |
+
amb_tonejs <- \(
|
15 |
+
id,
|
16 |
+
button_text,
|
17 |
+
pitch_name,
|
18 |
+
pitch_octave,
|
19 |
+
duration_value,
|
20 |
+
duration_unit,
|
21 |
+
duration_dotted = ""
|
22 |
+
) {
|
23 |
+
pitch <- paste0(pitch_name, pitch_octave, collapse = "")
|
24 |
+
dotted <- if (!is.null(duration_dotted)) { "." } else { "" }
|
25 |
+
duration <- paste0(duration_value, duration_unit, dotted, collapse = "")
|
26 |
+
script_chr <- paste0('
|
27 |
+
document.querySelector("#', id, '")?.addEventListener("click", async () => {
|
28 |
+
const synth = new Tone.Synth().toDestination();
|
29 |
+
synth.triggerAttackRelease("', pitch, '", "', duration, '");
|
30 |
+
await Tone.start();
|
31 |
+
console.log("audio is ready");
|
32 |
+
});',
|
33 |
+
collapse = ""
|
34 |
+
)
|
35 |
+
div(
|
36 |
+
class = paste0("amb_tonejs ", id),
|
37 |
+
style = "margin : 10px; float: left;",
|
38 |
+
button(id = id, button_text),
|
39 |
+
script(HTML(script_chr)),
|
40 |
+
a("x", style = "color: red; text-decoration: none", href = "/", hx_delete="/delete", hx_confirm = glue('Are you sure you want to delete "{button_text}"?'), hx_swap = "outerHTML", hx_target = glue(".{id}"))
|
41 |
+
)
|
42 |
+
}
|
43 |
+
|
44 |
+
#' Starting the app and defining the routes
|
45 |
+
app <- ambhtmx(host = "0.0.0.0", port = "7860")$app$
|
46 |
+
get("/", \(req, res){
|
47 |
+
div(
|
48 |
+
id = "page", style = "margin: 20px", h1(page_title),
|
49 |
+
div(id = "main",
|
50 |
+
div(
|
51 |
+
style ="margin-bottom: 10px",
|
52 |
+
span("Pitch name", div(
|
53 |
+
label(input(name = "pitch_name", type = "radio", value = "A", "A", checked = "checked")),
|
54 |
+
label(input(name = "pitch_name", type = "radio", value = "B", "B")),
|
55 |
+
label(input(name = "pitch_name", type = "radio", value = "C", "C")),
|
56 |
+
label(input(name = "pitch_name", type = "radio", value = "D", "D")),
|
57 |
+
label(input(name = "pitch_name", type = "radio", value = "E", "E")),
|
58 |
+
label(input(name = "pitch_name", type = "radio", value = "F", "F"))
|
59 |
+
))
|
60 |
+
),
|
61 |
+
div(
|
62 |
+
style ="margin-bottom: 10px",
|
63 |
+
label("Pitch octave", div(
|
64 |
+
input(name = "pitch_octave", type = "range", min = 0, max = 9, value = 4)
|
65 |
+
))
|
66 |
+
),
|
67 |
+
div(
|
68 |
+
style ="margin-bottom: 10px",
|
69 |
+
label("Duration value", div(
|
70 |
+
input(name = "duration_value", type = "range", min = 0.25, max = 8, step = 0.25, value = 0.25)
|
71 |
+
))
|
72 |
+
),
|
73 |
+
div(
|
74 |
+
style ="margin-bottom: 10px",
|
75 |
+
span("Duration unit", div(
|
76 |
+
label(input(name = "duration_unit", type = "radio", value = "n", "note", checked = "checked")),
|
77 |
+
label(input(name = "duration_unit", type = "radio", value = "t", "triplet")),
|
78 |
+
label(input(name = "duration_unit", type = "radio", value = "m", "measures"))
|
79 |
+
))
|
80 |
+
),
|
81 |
+
div(
|
82 |
+
style ="margin-bottom: 10px",
|
83 |
+
label(
|
84 |
+
input(name = "duration_dotted", type = "checkbox", value = "."),
|
85 |
+
"Duration dotted",
|
86 |
+
)
|
87 |
+
),
|
88 |
+
div(
|
89 |
+
style = "margin: 10px",
|
90 |
+
button(
|
91 |
+
"Add",
|
92 |
+
style = "margin-right: 20px",
|
93 |
+
hx_post = "/add",
|
94 |
+
hx_include = '[name="pitch_name"], [name="pitch_octave"], [name="duration_value"],[name="duration_unit"], [name="duration_dotted"]',
|
95 |
+
hx_vals = 'js:{id: document.querySelectorAll(".amb_tonejs").length + 1}',
|
96 |
+
hx_target = "#list",
|
97 |
+
hx_swap = "beforeend"
|
98 |
+
),
|
99 |
+
button(
|
100 |
+
"Reset",
|
101 |
+
hx_delete = "/delete",
|
102 |
+
hx_target = "#list",
|
103 |
+
hx_swap = "innerHTML",
|
104 |
+
hx_confirm = glue('Are you sure you want to reset all the notes?')
|
105 |
+
)
|
106 |
+
),
|
107 |
+
div(
|
108 |
+
id = "list",
|
109 |
+
amb_tonejs(
|
110 |
+
id = "amb_tonejs_1",
|
111 |
+
"Play c4 for 4n",
|
112 |
+
pitch_name = 'c',
|
113 |
+
pitch_octave = '4',
|
114 |
+
duration_value = 4,
|
115 |
+
duration_unit = 'n'
|
116 |
+
),
|
117 |
+
amb_tonejs(
|
118 |
+
id = "amb_tonejs_2",
|
119 |
+
"Play c5 for 8n",
|
120 |
+
pitch_name = 'c',
|
121 |
+
pitch_octave = '5',
|
122 |
+
duration_value = 8,
|
123 |
+
duration_unit = 'n'
|
124 |
+
)
|
125 |
+
)
|
126 |
+
)
|
127 |
+
) |>
|
128 |
+
send_page(res)
|
129 |
+
})$
|
130 |
+
post("/add", \(req, res) {
|
131 |
+
tryCatch(
|
132 |
+
{
|
133 |
+
params <- parse_multipart(req)
|
134 |
+
print(params)
|
135 |
+
amb_tonejs_id <- paste0("amb_tonejs_", params$id, collapse = "")
|
136 |
+
pitch <- paste0(params$pitch_name, params$pitch_octave, collapse = "")
|
137 |
+
dotted <- if (!is.null(params$duration_dotted)) { "." } else { "" }
|
138 |
+
duration <- paste0(params$duration_value, params$duration_unit, dotted, collapse = "")
|
139 |
+
text <- glue("Play {pitch} for {duration}")
|
140 |
+
html_tags <- amb_tonejs(
|
141 |
+
id = amb_tonejs_id,
|
142 |
+
glue("Play {pitch} for {duration}"),
|
143 |
+
pitch_name = params$pitch_name,
|
144 |
+
pitch_octave = params$pitch_octave,
|
145 |
+
duration_value = params$duration_value,
|
146 |
+
duration_unit = params$duration_unit,
|
147 |
+
duration_dotted = params$duration_dotted
|
148 |
+
) |>
|
149 |
+
send_tags(res)
|
150 |
+
},
|
151 |
+
error = \(e) {
|
152 |
+
print(e)
|
153 |
+
res$send("Error")
|
154 |
+
}
|
155 |
+
)
|
156 |
+
})$
|
157 |
+
delete("/delete", \(req, res) {
|
158 |
+
res$send("")
|
159 |
+
})
|
160 |
+
|
161 |
+
app$start(open = FALSE)
|
deploy_hf.sh
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
echo `date` > last_depoy.txt
|
2 |
+
git add last_depoy.txt
|
3 |
+
git commit -m "deploy"
|
4 |
+
git push hf main
|
docker_rm.sh
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
(docker container rm -f ambhtmx-tonejs-container || true) \
|
2 |
+
&& (docker rmi $(docker images --format '{{.Repository}}:{{.ID}}'| egrep 'ambhtmx-tonejs-image' | cut -d':' -f2 | uniq) --force || true)
|
docker_run.sh
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
(docker build -f Dockerfile -t ambhtmx-tonejs-image . || true) \
|
2 |
+
&& docker run --env-file=.Renviron -p 7860:7860 --name ambhtmx-tonejs-container --rm ambhtmx-tonejs-image
|
last_depoy.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
mar 06 ago 2024 17:29:11 CEST
|