jrosell commited on
Commit
f9955c0
·
0 Parent(s):

My changes

Browse files
Files changed (12) hide show
  1. .gitattributes +35 -0
  2. .gitignore +3 -0
  3. Dockerfile +73 -0
  4. README.md +69 -0
  5. app.R +111 -0
  6. deploy_hf.sh +4 -0
  7. docker_rm.sh +2 -0
  8. docker_run.sh +8 -0
  9. last_depoy.txt +1 -0
  10. output/what.txt +5 -0
  11. test.html +77 -0
  12. what.txt +5 -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 jrosell/ambhtmx 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,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ambhtmx.artyom
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
+ See the demo here:
20
+
21
+ * Direct URL to the deployed app: https://jrosell-ambhtmx-artyom.hf.space/
22
+ * Space URL: https://huggingface.co/spaces/jrosell/ambhtmx.artyom
23
+
24
+ Or test it locally:
25
+
26
+ ```
27
+ git clone [email protected]:jrosell/ambhtmx.artyom.git
28
+ cd ambhtmx.artyom
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 branch -M main
50
+ git remote add origin [email protected]:jrosell/ambhtmx.artyom.git
51
+ git remote add gh [email protected]:jrosell/ambhtmx.artyom.git
52
+ git remote add hf [email protected]:spaces/jrosell/ambhtmx.artyom
53
+ git remote -v
54
+ ```
55
+
56
+ Then, to depoly to Hugging Face Spaces run:
57
+
58
+ ```
59
+ bash deploy_hf.sh
60
+ ```
61
+
62
+ ## Troubleshooting
63
+
64
+ Kown issues:
65
+
66
+ * Only updates when refreshing the whole page. WIP should rerender on innerHTML replace.
67
+
68
+ 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).
69
+
app.R ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # remotes::install_github("jrosell/ambhtmx", force = TRUE)
2
+ library(ambhtmx)
3
+
4
+ what_file <- "output/what.txt"
5
+ invisible(!dir.exists("output") && dir.create("output"))
6
+
7
+ page_title <- "ambhtmx artyom example"
8
+
9
+ head_tags <- htmltools::tagList(
10
+ tags$link(href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css", rel = "stylesheet", integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH", crossorigin="anonymous"),
11
+ tags$script(src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js", integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz", crossorigin="anonymous"),
12
+ 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>'),
13
+ htmltools::HTML('<script src="https://cdn.jsdelivr.net/gh/sdkcarlos/artyom.js@master/build/artyom.window.min.js"></script>'),
14
+ htmltools::HTML(' <script>window.artyom = window.artyom || new Artyom();</script>')
15
+ )
16
+
17
+ amb_artyom <- \(lang, redirect_sel, accepts_name) {
18
+ ambhtmx::script_tpl(
19
+ lang = lang,
20
+ redirect_sel = redirect_sel,
21
+ accepts_name = accepts_name,
22
+ raw_content = htmlwidgets::JS('
23
+ artyom.addCommands([{
24
+ description:"It will save the text it recognizes.",
25
+ indexes: ["*"],
26
+ smart: true,
27
+ action : function(i, wildcard, sentence){
28
+ if(wildcard.includes("stop listening")){
29
+ document.querySelector(\'[name="{accepts_name}"]\').checked = false;
30
+ console.log("Stop listening checked")
31
+ }
32
+ if(document.querySelector(\'[name="{accepts_name}"]\').checked) {
33
+ var sel = document.querySelector("#listening-text");
34
+ sel.innerHTML = sel.innerHTML + "\\n" + wildcard;
35
+ var xhr = new XMLHttpRequest()
36
+ var formData = new FormData();
37
+ formData.append("what", wildcard);
38
+ xhr.open("POST", "/listen")
39
+ // xhr.setRequestHeader("Content-Type", "multipart/form-data")
40
+ // xhr.setRequestHeader("Accept", "multipart/form-data")
41
+ xhr.send(formData)
42
+ }
43
+ if(wildcard.includes("start listening")){
44
+ document.querySelector(\'[name="{accepts_name}"]\').checked = true;
45
+ console.log("Start listening checked")
46
+ }
47
+ }
48
+ }]);
49
+ artyom.redirectRecognizedTextOutput(function(text, isFinal){
50
+ var sel = document.querySelector("{redirect_sel}")
51
+ if(isFinal){
52
+ sel.innerHTML = "";
53
+ }else{
54
+ sel.innerHTML = text;
55
+ }
56
+ });
57
+ document.addEventListener("DOMContentLoaded", function(){
58
+ artyom.initialize({
59
+ lang: "{lang}",
60
+ debug: true,
61
+ continuous: true,
62
+ listen: true
63
+ });
64
+ });
65
+ ')
66
+ )
67
+ }
68
+
69
+ #' Starting the app and defining the routes
70
+ app <- ambhtmx(host = "0.0.0.0", port = "7860")$app$
71
+ get("/", \(req, res){
72
+ div(
73
+ id = "page",
74
+ style = "margin: 20px",
75
+ h1("Speech recognition example with artyom.js"),
76
+ p(strong("Say 'start listening' to start capturing what you say and 'stop listening' to stop.")),
77
+ div(
78
+ id = "main",
79
+ div(
80
+ style ="margin-bottom: 10px",
81
+ div(p("Recognizing text: ", span(id = "recognized-text"))),
82
+ div(label(
83
+ "Captured text",
84
+ tags$br(),
85
+ HTML("<textarea rows=10 cols=40 id='listening-text'></textarea>")
86
+ )),
87
+ div(label(input(name="accepts", type = "checkbox", style = "margin-right: 10px", "listenining")))
88
+ ),
89
+ amb_artyom(
90
+ lang = "en-US",
91
+ redirect_sel = "#recognized-text",
92
+ accepts_name = "accepts"
93
+ )
94
+ )
95
+ ) |>
96
+ send_page(res)
97
+ })$
98
+ post("/listen", \(req, res) {
99
+ params <- parse_multipart(req)
100
+ what <- params$what
101
+ cat(glue("\nwhat: {what}\n\n"))
102
+ write(what, file = what_file, append = TRUE)
103
+ res$send(what)
104
+ })
105
+
106
+ app$start(open = FALSE)
107
+
108
+
109
+
110
+
111
+
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-artyom-container || true) \
2
+ && (docker rmi $(docker images --format '{{.Repository}}:{{.ID}}'| egrep 'ambhtmx-artyom-image' | cut -d':' -f2 | uniq) --force || true)
docker_run.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ mkdir -p $(pwd)/output
3
+ mkdir -p /run/secrets
4
+ echo $GITHUB_PAT /run/secrets/GITHUB_PAT
5
+ (docker build -f Dockerfile -t ambhtmx-artyom-image . || true) \
6
+ && docker run --env-file=.Renviron -p 7860:7860 --name ambhtmx-artyom-container \
7
+ -v $(pwd)/output:/workspace/output/:rw \
8
+ --rm ambhtmx-artyom-image
last_depoy.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ mar 06 ago 2024 17:29:11 CEST
output/what.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ what
2
+ how are you
3
+ are you ready
4
+ do you know if it's working
5
+ yeah it's working
test.html ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
7
+ <meta name="viewport" content="width=device-width" />
8
+ <title>Speech color changer</title>
9
+ <style>
10
+ body {background: white; }
11
+ #view-source {
12
+ position: fixed;
13
+ display: block;
14
+ right: 0;
15
+ bottom: 0;
16
+ margin-right: 40px;
17
+ margin-bottom: 40px;
18
+ z-index: 900;
19
+ }
20
+ </style>
21
+ <script src="https://cdn.jsdelivr.net/gh/jquery/[email protected]/dist/jquery.min.js"></script>
22
+ <script src="https://cdn.jsdelivr.net/gh/sdkcarlos/artyom.js@master/build/artyom.window.min.js"></script>
23
+ <script>
24
+ window.artyom = window.artyom || new Artyom();
25
+ </script>
26
+ </head>
27
+ <body>
28
+ <h1>Speech recognition</h1>
29
+ <div><p>Recognizing text: <span id='recognized-text'></span></p></div>
30
+ <div><label>Captured text<br><textarea rows=10 cols=40 id='listening-text'></textarea></h5></div>
31
+ <div><input name="accepts" type = "checkbox"> listenining</div>
32
+ <div id='commands-container'></div>
33
+ <script>
34
+ artyom.addCommands([
35
+ {
36
+ description:"It will save the text it recognizes.",
37
+ indexes: ["*"],
38
+ smart:true,
39
+ action : function(i, wildcard, sentence){
40
+ if(wildcard.includes("stop listening")){
41
+ $('[name="accepts"]').prop('checked', false);
42
+ console.log("Stop listening checked")
43
+ }
44
+ if($('[name="accepts"]').prop('checked') == true) {
45
+ var sel = $('#listening-text');
46
+ sel.html(sel.html()+'\n'+wildcard);
47
+ }
48
+ if(wildcard.includes("start listening")){
49
+ $('[name="accepts"]').prop('checked', true);
50
+ console.log("Start listening checked")
51
+ }
52
+ }
53
+ },
54
+ ]);
55
+ artyom.redirectRecognizedTextOutput(function(text, isFinal){
56
+ var sel = $('#recognized-text');
57
+ if(isFinal){
58
+ sel.html('');
59
+ }else{
60
+ sel.html(text);
61
+ }
62
+ });
63
+ function startArtyom() {
64
+ artyom.initialize({
65
+ lang:'en-US',
66
+ debug:true,
67
+ continuous:true,
68
+ listen:true,
69
+ executionKeyword:'now'
70
+ });
71
+ }
72
+ $(window).on("load", function(){
73
+ startArtyom();
74
+ });
75
+ </script>
76
+ </body>
77
+ </html>
what.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ how are you
2
+ are you ready
3
+ what are you doing
4
+ oh boy
5
+ that's incredible