jingyangcarl commited on
Commit
267a24c
Β·
1 Parent(s): 1390847
Files changed (5) hide show
  1. Dockerfile +56 -0
  2. README.md +4 -4
  3. app.py +17 -0
  4. environment.yml +7 -0
  5. run.sh +14 -0
Dockerfile ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM continuumio/anaconda3:main
2
+
3
+ # make sure cv2 can be loaded
4
+ RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
5
+
6
+ WORKDIR /code
7
+ COPY ./environment.yml /code/environment.yml
8
+
9
+ # Create the environment using the environment.yml file
10
+ RUN conda env create -f /code/environment.yml
11
+
12
+ # install pip packages to the gradio environment
13
+ # when adjusting the dockerfile on huggingface:
14
+ # - if the dockerfile is successfully compileds, a new space need to be initialized and push the changes accordingly
15
+ # - otherwise, you can commit to the failed build dockerfile for debugging
16
+ RUN conda run -n gradio pip install --upgrade pip
17
+ # RUN conda run -n gradio pip install diffusers["torch"] transformers accelerate xformers
18
+ # RUN conda run -n gradio pip install gradio
19
+ # RUN conda run -n gradio pip install controlnet-aux
20
+ # RUN conda install -n gradio pytorch3d -c pytorch3d -c conda-forge
21
+ # RUN conda install -n gradio -c conda-forge open-clip-torch pytorch-lightning
22
+ # RUN conda run -n gradio pip install trimesh xatlas scikit-learn opencv-python omegaconf
23
+
24
+ # Set the environment variable to use the gradio environment by default
25
+ # RUN echo "source activate gradio" > ~/.bashrc
26
+ # ENV PATH /opt/conda/envs/gradio/bin:$PATH
27
+
28
+ # Set up a new user named "user" with user ID 1000
29
+ RUN useradd -m -u 1000 user
30
+ # Switch to the "user" user
31
+ USER user
32
+ RUN conda create -n gradio-user python=3.11
33
+ RUN conda run -n gradio-user pip install --upgrade pip
34
+ # RUN conda install -n gradio-user pytorch3d=0.7.7 -c pytorch3d -c conda-forge
35
+ # RUN conda install -n gradio-user -c conda-forge open-clip-torch pytorch-lightning
36
+ RUN conda run -n gradio-user pip install diffusers transformers accelerate xformers controlnet-aux gradio spaces trimesh xatlas scikit-learn opencv-python matplotlib omegaconf
37
+
38
+ # Set home to the user's home directory
39
+ ENV HOME=/home/user \
40
+ PYTHONPATH=$HOME/app \
41
+ PYTHONUNBUFFERED=1 \
42
+ GRADIO_ALLOW_FLAGGING=never \
43
+ GRADIO_SERVER_NAME=0.0.0.0 \
44
+ GRADIO_THEME=huggingface \
45
+ SYSTEM=spaces
46
+ # Set the working directory to the user's home directory
47
+ WORKDIR $HOME/app
48
+
49
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
50
+ COPY --chown=user . $HOME/app
51
+
52
+ # download https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_depth.pth?download=true to $HOME/app/text2tex/models/ControlNet/models/control_sd15_depth.pth
53
+ RUN mkdir -p $HOME/app/text2tex/models/ControlNet/models && \
54
+ wget -O $HOME/app/text2tex/models/ControlNet/models/control_sd15_depth.pth https://huggingface.co/lllyasviel/ControlNet/resolve/main/models/control_sd15_depth.pth?download=true
55
+
56
+ CMD ["./run.sh"]
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Docker Test38
3
- emoji: πŸ¦€
4
- colorFrom: purple
5
- colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
  ---
 
1
  ---
2
+ title: Docker Test6
3
+ emoji: πŸ‘€
4
+ colorFrom: pink
5
+ colorTo: pink
6
  sdk: docker
7
  pinned: false
8
  ---
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+
4
+
5
+ def update(name):
6
+ return f"Welcome to Gradio, {name}!"
7
+
8
+
9
+ with gr.Blocks() as demo:
10
+ gr.Markdown("Start typing below and then click **Run** to see the output.")
11
+ with gr.Row():
12
+ inp = gr.Textbox(placeholder="What is your name?")
13
+ out = gr.Textbox()
14
+ btn = gr.Button("Run")
15
+ btn.click(fn=update, inputs=inp, outputs=out)
16
+
17
+ demo.launch()
environment.yml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ name: gradio
2
+ channels:
3
+ - conda-forge
4
+ - defaults
5
+ dependencies:
6
+ - python=3.11
7
+ - gradio
run.sh ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ CONDA_ENV=$(head -1 /code/environment.yml | cut -d" " -f2)
4
+ eval "$(conda shell.bash hook)"
5
+ conda activate gradio-user
6
+ export OMP_NUM_THREADS=4 # default is a wrong value: 7500m
7
+
8
+ conda install -n gradio-user pytorch3d=0.7.7 -c pytorch3d -c conda-forge
9
+ conda install -n gradio-user -c conda-forge open-clip-torch pytorch-lightning
10
+
11
+ # Start app.py
12
+ echo "Starting app.py..."
13
+ python -c "import torch; x=torch.rand(1, device='cuda'); print(x, x.device.type)"
14
+ python app.py