Spaces:
Sleeping
Sleeping
Sébastien De Greef
commited on
Commit
·
e7a2ae9
1
Parent(s):
4a4f086
Update .gitignore and add ollama install to Dockerfile
Browse files- .gitignore +2 -1
- Dockerfile +38 -13
- main.py +14 -4
- start_server.sh +9 -0
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
.venv
|
|
|
|
1 |
+
.venv/
|
2 |
+
__pycache__/
|
Dockerfile
CHANGED
@@ -1,28 +1,53 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
-
FROM python:3.9
|
5 |
|
6 |
-
WORKDIR /code
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
11 |
|
12 |
-
# Set up a new user named "user" with user ID 1000
|
13 |
-
RUN useradd -m -u 1000 user
|
14 |
|
15 |
-
|
|
|
|
|
16 |
USER user
|
17 |
|
18 |
-
|
19 |
ENV HOME=/home/user \
|
20 |
PATH=/home/user/.local/bin:$PATH
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Set the working directory to the user's home directory
|
23 |
WORKDIR $HOME/app
|
24 |
-
|
25 |
-
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
26 |
COPY --chown=user . $HOME/app
|
|
|
27 |
|
28 |
-
|
|
|
|
1 |
+
FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04
|
2 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
3 |
|
|
|
4 |
|
|
|
5 |
|
6 |
+
RUN rm -f /etc/apt/sources.list.d/*.list && \
|
7 |
+
apt-get update && apt-get install -y --no-install-recommends \
|
8 |
+
curl \
|
9 |
+
ca-certificates \
|
10 |
+
sudo \
|
11 |
+
git \
|
12 |
+
git-lfs \
|
13 |
+
zip \
|
14 |
+
unzip \
|
15 |
+
htop \
|
16 |
+
bzip2 \
|
17 |
+
libx11-6 \
|
18 |
+
build-essential \
|
19 |
+
libsndfile-dev \
|
20 |
+
software-properties-common \
|
21 |
+
gcc \
|
22 |
+
wget \
|
23 |
+
lshw \
|
24 |
+
python3-dev \
|
25 |
+
&& rm -rf /var/lib/apt/lists/*
|
26 |
|
|
|
27 |
|
|
|
|
|
28 |
|
29 |
+
RUN curl -fsSL https://ollama.com/install.sh | sh
|
30 |
+
|
31 |
+
RUN useradd -m -u 1000 user
|
32 |
USER user
|
33 |
|
34 |
+
|
35 |
ENV HOME=/home/user \
|
36 |
PATH=/home/user/.local/bin:$PATH
|
37 |
|
38 |
+
ENV CONDA_AUTO_UPDATE_CONDA=true \
|
39 |
+
PATH=$HOME/miniconda/bin:$PATH
|
40 |
+
|
41 |
+
RUN curl -sLo ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-py311_23.11.0-1-Linux-x86_64.sh \
|
42 |
+
&& chmod +x ~/miniconda.sh \
|
43 |
+
&& ~/miniconda.sh -b -p ~/miniconda \
|
44 |
+
&& rm ~/miniconda.sh \
|
45 |
+
&& conda clean -ya
|
46 |
+
|
47 |
# Set the working directory to the user's home directory
|
48 |
WORKDIR $HOME/app
|
|
|
|
|
49 |
COPY --chown=user . $HOME/app
|
50 |
+
RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt
|
51 |
|
52 |
+
RUN chmod +x $HOME/app/start_server.sh
|
53 |
+
ENTRYPOINT ["/home/user/app/start_server.sh"]
|
main.py
CHANGED
@@ -2,7 +2,7 @@ from langchain.schema import AIMessage, HumanMessage
|
|
2 |
import gradio as gr
|
3 |
from langchain_community.llms import Ollama
|
4 |
|
5 |
-
llm = Ollama(model="
|
6 |
|
7 |
def predict(message, history):
|
8 |
history_langchain_format = []
|
@@ -10,7 +10,17 @@ def predict(message, history):
|
|
10 |
history_langchain_format.append(HumanMessage(content=human))
|
11 |
history_langchain_format.append(AIMessage(content=ai))
|
12 |
history_langchain_format.append(HumanMessage(content=message))
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
from langchain_community.llms import Ollama
|
4 |
|
5 |
+
llm = Ollama(model="llama3:8b", timeout=1000)
|
6 |
|
7 |
def predict(message, history):
|
8 |
history_langchain_format = []
|
|
|
10 |
history_langchain_format.append(HumanMessage(content=human))
|
11 |
history_langchain_format.append(AIMessage(content=ai))
|
12 |
history_langchain_format.append(HumanMessage(content=message))
|
13 |
+
try:
|
14 |
+
caht_response = llm.invoke(history_langchain_format)
|
15 |
+
except Exception as e:
|
16 |
+
caht_response = "Error: " + str(e)
|
17 |
+
|
18 |
+
return caht_response
|
19 |
|
20 |
+
def run():
|
21 |
+
demo = gr.ChatInterface(predict)
|
22 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
23 |
+
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
run()
|
start_server.sh
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
# Start the background task
|
3 |
+
ollama serve &
|
4 |
+
|
5 |
+
ollama pull mistral:7b > /dev/null 2>&1
|
6 |
+
ollama pull llama3:8b > /dev/null 2>&1
|
7 |
+
|
8 |
+
# Start the Gradio app
|
9 |
+
python main.py
|