bmorphism nsarrazin HF staff commited on
Commit
e51ec8b
β€’
0 Parent(s):

Duplicate from huggingchat/chat-ui-template

Browse files

Co-authored-by: Nathan Sarrazin <nsarrazin@users.noreply.huggingface.co>

.env.local.template ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use .env.local to change these variables
2
+ # DO NOT EDIT THIS FILE WITH SENSITIVE DATA
3
+
4
+ MONGODB_URL=${MONGODB_URL}
5
+ MONGODB_DB_NAME=chat-ui
6
+ MONGODB_DIRECT_CONNECTION=false
7
+
8
+
9
+ COOKIE_NAME=chat-ui
10
+ HF_ACCESS_TOKEN=#hf_<token> from from https://huggingface.co/settings/token
11
+
12
+ # used to activate search with web functionality. disabled if not defined
13
+ SERPAPI_KEY=#your serpapi key here
14
+
15
+ # Parameters to enable "Sign in with HF"
16
+ OPENID_CLIENT_ID=
17
+ OPENID_CLIENT_SECRET=
18
+ OPENID_SCOPES="openid profile" # Add "email" for some providers like Google that do not provide preferred_username
19
+ OPENID_PROVIDER_URL=https://huggingface.co # for Google, use https://accounts.google.com
20
+
21
+
22
+ # 'name', 'userMessageToken', 'assistantMessageToken' are required
23
+ MODELS=`[
24
+ {
25
+ "name": "${MODEL_NAME}",
26
+ "userMessageToken": "<|prompter|>",
27
+ "assistantMessageToken": "<|assistant|>",
28
+ "messageEndToken": "<|endoftext|>",
29
+ "preprompt": "",
30
+ "promptExamples": [
31
+ {
32
+ "title": "Python Fibonacci",
33
+ "prompt": "How can I write a Python function to generate the nth Fibonacci number?"
34
+ }, {
35
+ "title": "What is a meme?",
36
+ "prompt": "What is a meme, and what's the history behind this word?"
37
+ }, {
38
+ "title": "Regex",
39
+ "prompt": "Create a regex to extract dates from logs"
40
+ }
41
+ ],
42
+ "endpoints": [
43
+ {
44
+ "url": "http://127.0.0.1:8080"
45
+ }
46
+ ],
47
+ "parameters": ${MODEL_PARAMS}
48
+ }
49
+ ]`
50
+ OLD_MODELS=`[]`# any removed models, `{ name: string, displayName?: string, id?: string }`
51
+
52
+ PUBLIC_ORIGIN=${SPACE_HOST}
53
+ PUBLIC_SHARE_PREFIX=${SPACE_HOST}/r
54
+ PUBLIC_GOOGLE_ANALYTICS_ID=#G-XXXXXXXX / Leave empty to disable
55
+ PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID=#UA-XXXXXXXX-X / Leave empty to disable
56
+ PUBLIC_ANNOUNCEMENT_BANNERS=`[
57
+ {
58
+ "title": "Chat UI is now open sourced on GitHub",
59
+ "linkTitle": "GitHub repo",
60
+ "linkHref": "https://github.com/huggingface/chat-ui"
61
+ }
62
+ ]`
63
+
64
+ PARQUET_EXPORT_DATASET=
65
+ PARQUET_EXPORT_HF_TOKEN=
66
+ PARQUET_EXPORT_SECRET=
67
+
68
+ PUBLIC_APP_NAME=${APP_NAME} # name used as title throughout the app
69
+ PUBLIC_APP_ASSETS=chatui # used to find logos & favicons in static/$PUBLIC_APP_ASSETS
70
+ PUBLIC_APP_COLOR=${APP_COLOR} # can be any of tailwind colors: https://tailwindcss.com/docs/customizing-colors#default-color-palette
71
+ PUBLIC_APP_DATA_SHARING=#set to 1 to enable disclaimers & options about data sharing
72
+ PUBLIC_APP_DATA_DISCLAIMER=#set to 1 to enable disclaimers about model outputs
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ARG MODEL_NAME
2
+ ARG MODEL_PARAMS
3
+ ARG APP_COLOR
4
+ ARG APP_NAME
5
+
6
+
7
+ FROM node:19 as chatui-builder
8
+ ARG MODEL_NAME
9
+ ARG MODEL_PARAMS
10
+ ARG APP_COLOR
11
+ ARG APP_NAME
12
+
13
+ WORKDIR /app
14
+
15
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16
+ git gettext && \
17
+ rm -rf /var/lib/apt/lists/*
18
+
19
+
20
+ RUN git clone https://github.com/huggingface/chat-ui.git
21
+
22
+ WORKDIR /app/chat-ui
23
+
24
+
25
+ COPY .env.local.template .env.local.template
26
+
27
+ RUN mkdir defaults
28
+ ADD defaults /defaults
29
+ RUN chmod -R 777 /defaults
30
+ RUN --mount=type=secret,id=MONGODB_URL,mode=0444 \
31
+ MODEL_NAME="${MODEL_NAME:="$(cat /defaults/MODEL_NAME)"}" && export MODEL_NAME \
32
+ && MODEL_PARAMS="${MODEL_PARAMS:="$(cat /defaults/MODEL_PARAMS)"}" && export MODEL_PARAMS \
33
+ && APP_COLOR="${APP_COLOR:="$(cat /defaults/APP_COLOR)"}" && export APP_COLOR \
34
+ && APP_NAME="${APP_NAME:="$(cat /defaults/APP_NAME)"}" && export APP_NAME \
35
+ && MONGODB_URL=$(cat /run/secrets/MONGODB_URL > /dev/null | grep '^' || cat /defaults/MONGODB_URL) && export MONGODB_URL && \
36
+ echo "${MONGODB_URL}" && \
37
+ envsubst < ".env.local.template" > ".env.local" \
38
+ && rm .env.local.template
39
+
40
+
41
+
42
+ RUN --mount=type=cache,target=/app/.npm \
43
+ npm set cache /app/.npm && \
44
+ npm ci
45
+
46
+ RUN npm run build
47
+
48
+ FROM ghcr.io/huggingface/text-generation-inference:0.9.4
49
+
50
+ ARG MODEL_NAME
51
+ ARG MODEL_PARAMS
52
+ ARG APP_COLOR
53
+ ARG APP_NAME
54
+
55
+ ENV TZ=Europe/Paris \
56
+ PORT=3000
57
+
58
+
59
+
60
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
61
+ gnupg \
62
+ curl \
63
+ gettext && \
64
+ rm -rf /var/lib/apt/lists/*
65
+ COPY entrypoint.sh.template entrypoint.sh.template
66
+
67
+ RUN mkdir defaults
68
+ ADD defaults /defaults
69
+ RUN chmod -R 777 /defaults
70
+
71
+ RUN --mount=type=secret,id=MONGODB_URL,mode=0444 \
72
+ MODEL_NAME="${MODEL_NAME:="$(cat /defaults/MODEL_NAME)"}" && export MODEL_NAME \
73
+ && MODEL_PARAMS="${MODEL_PARAMS:="$(cat /defaults/MODEL_PARAMS)"}" && export MODEL_PARAMS \
74
+ && APP_COLOR="${APP_COLOR:="$(cat /defaults/APP_COLOR)"}" && export APP_COLOR \
75
+ && APP_NAME="${APP_NAME:="$(cat /defaults/APP_NAME)"}" && export APP_NAME \
76
+ && MONGODB_URL=$(cat /run/secrets/MONGODB_URL > /dev/null | grep '^' || cat /defaults/MONGODB_URL) && export MONGODB_URL && \
77
+ envsubst < "entrypoint.sh.template" > "entrypoint.sh" \
78
+ && rm entrypoint.sh.template
79
+
80
+
81
+ RUN curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
82
+ gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
83
+ --dearmor
84
+
85
+ RUN echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list
86
+
87
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
88
+ mongodb-org && \
89
+ rm -rf /var/lib/apt/lists/*
90
+
91
+ RUN mkdir -p /data/db
92
+ RUN chown -R 1000:1000 /data
93
+
94
+ RUN curl -fsSL https://deb.nodesource.com/setup_19.x | /bin/bash -
95
+
96
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
97
+ nodejs && \
98
+ rm -rf /var/lib/apt/lists/*
99
+
100
+ RUN mkdir /app
101
+ RUN chown -R 1000:1000 /app
102
+
103
+ RUN useradd -m -u 1000 user
104
+
105
+ # Switch to the "user" user
106
+ USER user
107
+
108
+ ENV HOME=/home/user \
109
+ PATH=/home/user/.local/bin:$PATH
110
+
111
+ RUN npm config set prefix /home/user/.local
112
+ RUN npm install -g pm2
113
+
114
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/node_modules /app/node_modules
115
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/package.json /app/package.json
116
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/build /app/build
117
+
118
+ ENTRYPOINT ["/bin/bash"]
119
+ CMD ["entrypoint.sh"]
120
+
121
+
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Chat Ui Template
3
+ emoji: πŸš€
4
+ colorFrom: indigo
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ app_port: 3000
9
+ suggested_hardware: a10g-small
10
+ duplicated_from: huggingchat/chat-ui-template
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
defaults/APP_COLOR ADDED
@@ -0,0 +1 @@
 
 
1
+ blue
defaults/APP_NAME ADDED
@@ -0,0 +1 @@
 
 
1
+ ChatUI
defaults/MODEL_NAME ADDED
@@ -0,0 +1 @@
 
 
1
+ OpenAssistant/falcon-7b-sft-top1-696
defaults/MODEL_PARAMS ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "temperature": 0.9,
3
+ "top_p": 0.95,
4
+ "repetition_penalty": 1.2,
5
+ "top_k": 50,
6
+ "truncate": 1000,
7
+ "max_new_tokens": 1024
8
+ }
defaults/MONGODB_URL ADDED
@@ -0,0 +1 @@
 
 
1
+ mongodb://127.0.0.1:27017
entrypoint.sh.template ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Start the local Mongo database
4
+ mongod &
5
+
6
+ # Start the text-generation-inference process
7
+ text-generation-launcher --model-id ${MODEL_NAME} --num-shard 1 --port 8080 --trust-remote-code &
8
+
9
+ # Wait for text-generation-inference to start
10
+ curl --retry 60 --retry-delay 10 --retry-connrefused http://127.0.0.1:8080/health
11
+
12
+ # Start the chat-ui process
13
+ pm2 start /app/build/index.js -i $CPU_CORES --no-daemon &
14
+
15
+ # Wait for any process to exit
16
+ wait -n
17
+
18
+ # Exit with status of process that exited first
19
+ exit $?