potamides commited on
Commit
116a187
β€’
1 Parent(s): 530237f

feat: add docker image and app

Browse files
Files changed (3) hide show
  1. Dockerfile +82 -0
  2. README.md +2 -1
  3. app.py +28 -0
Dockerfile ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Custom docker image for DeTikZify. The default HF Spaces GPU image installs a
2
+ # tex live version that is too old for our needs, so we install the latest one
3
+ # oureselves.
4
+
5
+ ## system setup
6
+ # -----------------------------------------------------------------------------
7
+ FROM nvcr.io/nvidia/cuda:12.1.0-cudnn8-devel-ubuntu22.04
8
+
9
+ ARG DEBIAN_FRONTEND=noninteractive
10
+
11
+ Run apt update && apt install -y \
12
+ ghostscript \
13
+ poppler-utils \
14
+ git \
15
+ make \
16
+ build-essential \
17
+ libssl-dev \
18
+ zlib1g-dev \
19
+ libbz2-dev \
20
+ libreadline-dev \
21
+ libsqlite3-dev \
22
+ wget \
23
+ curl \
24
+ llvm \
25
+ libncursesw5-dev \
26
+ xz-utils \
27
+ tk-dev \
28
+ libxml2-dev \
29
+ libxmlsec1-dev \
30
+ libffi-dev \
31
+ liblzma-dev \
32
+ ffmpeg \
33
+ libsm6 \
34
+ libxext6 \
35
+ cmake \
36
+ libgl1-mesa-glx \
37
+ sudo
38
+
39
+ # install tex live 2023
40
+ ENV PATH=/opt/texbin:$PATH
41
+
42
+ RUN curl -LO https://github.com/scottkosty/install-tl-ubuntu/raw/master/install-tl-ubuntu \
43
+ && chmod +x ./install-tl-ubuntu \
44
+ && ./install-tl-ubuntu --repository 'https://ftp.math.utah.edu/pub/tex/historic/systems/texlive/2023/tlnet-final'\
45
+ && rm ./install-tl-ubuntu
46
+
47
+ ## setup user
48
+ # -----------------------------------------------------------------------------
49
+ RUN useradd -m -G users -u 1000 user
50
+
51
+ ENV HOME=/home/user \
52
+ PATH=/home/user/.local/bin:$PATH
53
+
54
+ WORKDIR $HOME/app
55
+
56
+ ## install python dependencies
57
+ # -----------------------------------------------------------------------------
58
+
59
+ # install pyenv
60
+ ENV PYENV_ROOT=/opt/pyenv
61
+ ENV PATH=$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
62
+
63
+ RUN curl https://pyenv.run | bash \
64
+ && chown -R root:users $PYENV_ROOT \
65
+ && chmod -R g+w $PYENV_ROOT
66
+
67
+ RUN pyenv install 3.10 \
68
+ && pyenv global 3.10 \
69
+ && pyenv rehash \
70
+ && pip install --no-cache-dir --upgrade setuptools wheel \
71
+ && pip install --no-cache-dir 'detikzify @ git+https://github.com/potamides/DeTikZify' \
72
+ && pip install --no-cache-dir flash-attn --no-build-isolation \
73
+ && pip install --no-cache-dir spaces
74
+
75
+ RUN chown -R user $HOME/app
76
+ COPY --chown=user . $HOME/app
77
+
78
+ ## launch app
79
+ # -----------------------------------------------------------------------------
80
+ USER user
81
+
82
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -1,11 +1,12 @@
1
  ---
2
  title: DeTikZify
3
- emoji: πŸ”₯
4
  colorFrom: pink
5
  colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
  license: apache-2.0
 
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: DeTikZify
3
+ emoji: πŸ“ˆ
4
  colorFrom: pink
5
  colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
  license: apache-2.0
9
+ suggested_hardware: a10g-small
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from os import getenv
2
+ from textwrap import dedent
3
+
4
+ import gradio as gr
5
+ from torch import cuda
6
+
7
+ from detikzify.webui import build_ui, make_light, BANNER
8
+
9
+ if is_public:=(getenv("SPACE_ID") == "nllg/DeTikZify") and not cuda.is_available():
10
+ center = ".gradio-container {text-align: center}"
11
+ with gr.Blocks(css=center, theme=make_light(gr.themes.Soft()), title="DeTikZify") as demo:
12
+ badge = "https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-xl.svg"
13
+ link = "https://huggingface.co/spaces/nllg/DeTikZify?duplicate=true"
14
+ html = f'<a style="display:inline-block" href="{link}"> <img src="{badge}" alt="Duplicate this Space"> </a>'
15
+ message = dedent("""\
16
+ The resources required by our models surpass those provided by Hugging
17
+ Face Spaces' free CPU tier. For full functionality, we suggest
18
+ duplicating this space using a paid private GPU runtime.
19
+ """)
20
+ gr.HTML(f'{BANNER}\n<p>{message}</p>\n{html}')
21
+ else:
22
+ use_big_models = cuda.is_available() and cuda.get_device_properties(0).total_memory > 15835660288
23
+ model = f"detikzify-ds-{'7' if use_big_models else '1.3'}b"
24
+ algorithm = "sampling" if is_public else "mcts"
25
+ demo = build_ui(lock=is_public, model=model, algorithm=algorithm, light=True).queue()
26
+
27
+ if __name__ == "__main__":
28
+ demo.launch(server_name="0.0.0.0", server_port=7860)