bartowski commited on
Commit
110e4da
·
1 Parent(s): 9c7f615

Add dockerfile and app.py

Browse files
Files changed (2) hide show
  1. Dockerfile +61 -0
  2. app.py +52 -0
Dockerfile ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04
2
+ ENV DEBIAN_FRONTEND=noninteractive
3
+ RUN apt-get update && \
4
+ apt-get upgrade -y && \
5
+ apt-get install -y --no-install-recommends \
6
+ git \
7
+ git-lfs \
8
+ wget \
9
+ curl \
10
+ # python build dependencies \
11
+ build-essential \
12
+ libssl-dev \
13
+ zlib1g-dev \
14
+ libbz2-dev \
15
+ libreadline-dev \
16
+ libsqlite3-dev \
17
+ libncursesw5-dev \
18
+ xz-utils \
19
+ tk-dev \
20
+ libxml2-dev \
21
+ libxmlsec1-dev \
22
+ libffi-dev \
23
+ liblzma-dev \
24
+ # gradio dependencies \
25
+ ffmpeg
26
+
27
+ RUN useradd -m -u 1000 user
28
+ USER user
29
+ ENV HOME=/home/user \
30
+ PATH=/home/user/.local/bin:${PATH}
31
+ WORKDIR ${HOME}/app
32
+
33
+ RUN curl https://pyenv.run | bash
34
+ ENV PATH=${HOME}/.pyenv/shims:${HOME}/.pyenv/bin:${PATH}
35
+ ARG PYTHON_VERSION=3.10.13
36
+ RUN pyenv install ${PYTHON_VERSION} && \
37
+ pyenv global ${PYTHON_VERSION} && \
38
+ pyenv rehash && \
39
+ pip install --no-cache-dir -U pip setuptools wheel && \
40
+ pip install "huggingface-hub" "hf-transfer"
41
+
42
+ COPY --chown=1000 . ${HOME}/app
43
+ RUN git clone https://github.com/ggerganov/llama.cpp && \
44
+ cd llama.cpp && \
45
+ make clean && \
46
+ LLAMA_CUDA=1 make
47
+
48
+ RUN pip install -r llama.cpp/requirements.txt
49
+
50
+ ENV PYTHONPATH=${HOME}/app \
51
+ PYTHONUNBUFFERED=1 \
52
+ HF_HUB_ENABLE_HF_TRANSFER=1 \
53
+ GRADIO_ALLOW_FLAGGING=never \
54
+ GRADIO_NUM_PORTS=1 \
55
+ GRADIO_SERVER_NAME=0.0.0.0 \
56
+ GRADIO_THEME=huggingface \
57
+ TQDM_POSITION=-1 \
58
+ TQDM_MININTERVAL=1 \
59
+ SYSTEM=spaces
60
+
61
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+
4
+ from huggingface_hub import HfApi, snapshot_download
5
+
6
+ api = HfApi()
7
+
8
+
9
+ def process_model(model_id: str, file_path: str, key: str, value: str, hf_token):
10
+
11
+ MODEL_NAME = model_id.split("/")[-1]
12
+
13
+ FILE_NAME = file_path.split("/")[-1]
14
+
15
+ snapshot_download(
16
+ repo_id=model_id,
17
+ allow_patterns=file_path,
18
+ local_dir=f"{MODEL_NAME}",
19
+ )
20
+ print("Model downloaded successully!")
21
+
22
+ metadata_update = f"python llama.cpp/gguf-py/scripts/gguf_set_metadata.py {MODEL_NAME}/{file_path} {key} {value}"
23
+ subprocess.run(metadata_update, shell=True)
24
+ print(f"Model metadata {key} updated to {value} successully!")
25
+
26
+ # Upload gguf files
27
+ api.upload_folder(
28
+ folder_path=MODEL_NAME,
29
+ repo_id=model_id,
30
+ allow_patterns=["*.gguf", "$.md"],
31
+ token=hf_token,
32
+ )
33
+ print("Uploaded successfully!")
34
+
35
+ return "Processing complete."
36
+
37
+
38
+ # Create Gradio interface
39
+ iface = gr.Interface(
40
+ fn=process_model,
41
+ inputs=[
42
+ gr.Textbox(lines=1, label="Model ID"),
43
+ gr.Textbox(lines=1, label="File path"),
44
+ gr.Textbox(lines=1, label="Key"),
45
+ gr.Textbox(lines=1, label="Value"),
46
+ gr.Textbox(lines=1, label="Token"),
47
+ ],
48
+ outputs="text",
49
+ )
50
+
51
+ # Launch the interface
52
+ iface.launch(debug=True)