Pierre-Carl Langlais nsarrazin HF staff commited on
Commit
ef71d12
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,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "chatPromptTemplate": "${MODEL_PROMPT_TEMPLATE}",
27
+ "preprompt": "",
28
+ "promptExamples": [
29
+ {
30
+ "title": "Python Fibonacci",
31
+ "prompt": "How can I write a Python function to generate the nth Fibonacci number?"
32
+ }, {
33
+ "title": "What is a meme?",
34
+ "prompt": "What is a meme, and what's the history behind this word?"
35
+ }, {
36
+ "title": "Regex",
37
+ "prompt": "Create a regex to extract dates from logs"
38
+ }
39
+ ],
40
+ "endpoints": [
41
+ {
42
+ "url": "http://127.0.0.1:8080"
43
+ }
44
+ ],
45
+ "parameters": ${MODEL_PARAMS}
46
+ }
47
+ ]`
48
+ OLD_MODELS=`[]`# any removed models, `{ name: string, displayName?: string, id?: string }`
49
+
50
+ PUBLIC_ORIGIN=${SPACE_HOST}
51
+ PUBLIC_SHARE_PREFIX=${SPACE_HOST}/r
52
+ PUBLIC_GOOGLE_ANALYTICS_ID=#G-XXXXXXXX / Leave empty to disable
53
+ PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID=#UA-XXXXXXXX-X / Leave empty to disable
54
+ PUBLIC_ANNOUNCEMENT_BANNERS=`[
55
+ {
56
+ "title": "Chat UI is now open sourced on GitHub",
57
+ "linkTitle": "GitHub repo",
58
+ "linkHref": "https://github.com/huggingface/chat-ui"
59
+ }
60
+ ]`
61
+
62
+ PARQUET_EXPORT_DATASET=
63
+ PARQUET_EXPORT_HF_TOKEN=
64
+ PARQUET_EXPORT_SECRET=
65
+
66
+ PUBLIC_APP_NAME=${APP_NAME} # name used as title throughout the app
67
+ PUBLIC_APP_ASSETS=chatui # used to find logos & favicons in static/$PUBLIC_APP_ASSETS
68
+ PUBLIC_APP_COLOR=${APP_COLOR} # can be any of tailwind colors: https://tailwindcss.com/docs/customizing-colors#default-color-palette
69
+ PUBLIC_APP_DATA_SHARING=#set to 1 to enable disclaimers & options about data sharing
70
+ 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,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ARG MODEL_NAME
2
+ ARG MODEL_PARAMS
3
+ ARG MODEL_PROMPT_TEMPLATE
4
+ ARG APP_COLOR
5
+ ARG APP_NAME
6
+
7
+
8
+ FROM node:19 as chatui-builder
9
+ ARG MODEL_NAME
10
+ ARG MODEL_PARAMS
11
+ ARG APP_COLOR
12
+ ARG APP_NAME
13
+ ARG MODEL_PROMPT_TEMPLATE
14
+
15
+ WORKDIR /app
16
+
17
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
18
+ git gettext && \
19
+ rm -rf /var/lib/apt/lists/*
20
+
21
+
22
+ RUN git clone https://github.com/huggingface/chat-ui.git
23
+
24
+ WORKDIR /app/chat-ui
25
+
26
+
27
+ COPY .env.local.template .env.local.template
28
+
29
+ RUN mkdir defaults
30
+ ADD defaults /defaults
31
+ RUN chmod -R 777 /defaults
32
+ RUN --mount=type=secret,id=MONGODB_URL,mode=0444 \
33
+ MODEL_NAME="${MODEL_NAME:="$(cat /defaults/MODEL_NAME)"}" && export MODEL_NAME \
34
+ && MODEL_PARAMS="${MODEL_PARAMS:="$(cat /defaults/MODEL_PARAMS)"}" && export MODEL_PARAMS \
35
+ && MODEL_PROMPT_TEMPLATE="${MODEL_PROMPT_TEMPLATE:="$(cat /defaults/MODEL_PROMPT_TEMPLATE)"}" && export MODEL_PROMPT_TEMPLATE \
36
+ && APP_COLOR="${APP_COLOR:="$(cat /defaults/APP_COLOR)"}" && export APP_COLOR \
37
+ && APP_NAME="${APP_NAME:="$(cat /defaults/APP_NAME)"}" && export APP_NAME \
38
+ && MONGODB_URL=$(cat /run/secrets/MONGODB_URL > /dev/null | grep '^' || cat /defaults/MONGODB_URL) && export MONGODB_URL && \
39
+ echo "${MONGODB_URL}" && \
40
+ envsubst < ".env.local.template" > ".env.local" \
41
+ && rm .env.local.template
42
+
43
+
44
+
45
+ RUN --mount=type=cache,target=/app/.npm \
46
+ npm set cache /app/.npm && \
47
+ npm ci
48
+
49
+ RUN npm run build
50
+
51
+ FROM ghcr.io/huggingface/text-generation-inference:latest
52
+
53
+ ARG MODEL_NAME
54
+ ARG MODEL_PARAMS
55
+ ARG MODEL_PROMPT_TEMPLATE
56
+ ARG APP_COLOR
57
+ ARG APP_NAME
58
+
59
+ ENV TZ=Europe/Paris \
60
+ PORT=3000
61
+
62
+
63
+
64
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
65
+ gnupg \
66
+ curl \
67
+ gettext && \
68
+ rm -rf /var/lib/apt/lists/*
69
+ COPY entrypoint.sh.template entrypoint.sh.template
70
+
71
+ RUN mkdir defaults
72
+ ADD defaults /defaults
73
+ RUN chmod -R 777 /defaults
74
+
75
+ RUN --mount=type=secret,id=MONGODB_URL,mode=0444 \
76
+ MODEL_NAME="${MODEL_NAME:="$(cat /defaults/MODEL_NAME)"}" && export MODEL_NAME \
77
+ && MODEL_PARAMS="${MODEL_PARAMS:="$(cat /defaults/MODEL_PARAMS)"}" && export MODEL_PARAMS \
78
+ && MODEL_PROMPT_TEMPLATE="${MODEL_PROMPT_TEMPLATE:="$(cat /defaults/MODEL_PROMPT_TEMPLATE)"}" && export MODEL_PROMPT_TEMPLATE \
79
+ && APP_COLOR="${APP_COLOR:="$(cat /defaults/APP_COLOR)"}" && export APP_COLOR \
80
+ && APP_NAME="${APP_NAME:="$(cat /defaults/APP_NAME)"}" && export APP_NAME \
81
+ && MONGODB_URL=$(cat /run/secrets/MONGODB_URL > /dev/null | grep '^' || cat /defaults/MONGODB_URL) && export MONGODB_URL && \
82
+ envsubst < "entrypoint.sh.template" > "entrypoint.sh" \
83
+ && rm entrypoint.sh.template
84
+
85
+
86
+ RUN curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
87
+ gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
88
+ --dearmor
89
+
90
+ 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
91
+
92
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
93
+ mongodb-org && \
94
+ rm -rf /var/lib/apt/lists/*
95
+
96
+ RUN mkdir -p /data/db
97
+ RUN chown -R 1000:1000 /data
98
+
99
+ RUN curl -fsSL https://deb.nodesource.com/setup_19.x | /bin/bash -
100
+
101
+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
102
+ nodejs && \
103
+ rm -rf /var/lib/apt/lists/*
104
+
105
+ RUN mkdir /app
106
+ RUN chown -R 1000:1000 /app
107
+
108
+ RUN useradd -m -u 1000 user
109
+
110
+ # Switch to the "user" user
111
+ USER user
112
+
113
+ ENV HOME=/home/user \
114
+ PATH=/home/user/.local/bin:$PATH
115
+
116
+ RUN npm config set prefix /home/user/.local
117
+ RUN npm install -g pm2
118
+
119
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/node_modules /app/node_modules
120
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/package.json /app/package.json
121
+ COPY --from=chatui-builder --chown=1000 /app/chat-ui/build /app/build
122
+
123
+ ENTRYPOINT ["/bin/bash"]
124
+ CMD ["entrypoint.sh"]
125
+
126
+
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ---
11
+
12
+ 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/MODEL_PROMPT_TEMPLATE ADDED
@@ -0,0 +1 @@
 
 
1
+ <s>{{#each messages}}{{#ifUser}}[INST] {{#if @first}}{{#if @root.preprompt}}{{@root.preprompt}}\n{{/if}}{{/if}} {{content}} [/INST]{{/ifUser}}{{#ifAssistant}}{{content}}</s> {{/ifAssistant}}{{/each}}
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 $?