jingyangcarl commited on
Commit
b17cab7
·
1 Parent(s): d9cb8b3
Files changed (4) hide show
  1. Dockerfile +50 -0
  2. app.py +17 -0
  3. environment.yml +7 -0
  4. run.sh +14 -0
Dockerfile ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM continuumio/anaconda3:main
2
+
3
+ WORKDIR /code
4
+ COPY ./environment.yml /code/environment.yml
5
+
6
+ # Create the environment using the environment.yml file
7
+ RUN conda env create -f /code/environment.yml
8
+
9
+ # install pip packages to the gradio environment
10
+ # when adjusting the dockerfile on huggingface:
11
+ # - if the dockerfile is successfully compileds, a new space need to be initialized and push the changes accordingly
12
+ # - otherwise, you can commit to the failed build dockerfile for debugging
13
+ RUN conda run -n gradio pip install --upgrade pip
14
+ # RUN conda run -n gradio pip install diffusers["torch"] transformers accelerate xformers
15
+ # RUN conda run -n gradio pip install gradio
16
+ # RUN conda run -n gradio pip install controlnet-aux
17
+ # RUN conda install -n gradio pytorch3d -c pytorch3d -c conda-forge
18
+ # RUN conda install -n gradio -c conda-forge open-clip-torch pytorch-lightning
19
+ # RUN conda run -n gradio pip install trimesh xatlas scikit-learn opencv-python omegaconf
20
+
21
+ # Set the environment variable to use the gradio environment by default
22
+ # RUN echo "source activate gradio" > ~/.bashrc
23
+ # ENV PATH /opt/conda/envs/gradio/bin:$PATH
24
+
25
+ # Set up a new user named "user" with user ID 1000
26
+ RUN useradd -m -u 1000 user
27
+ # Switch to the "user" user
28
+ USER user
29
+
30
+ RUN conda create -n gradio-user python=3.11
31
+ RUN conda run -n gradio-user pip install --upgrade pip
32
+ # RUN conda install -n gradio-user pytorch3d=0.7.7 -c pytorch3d -c conda-forge
33
+ # RUN conda install -n gradio-user -c conda-forge open-clip-torch pytorch-lightning
34
+ RUN conda run -n gradio-user pip install diffusers transformers accelerate xformers controlnet-aux gradio trimesh xatlas scikit-learn opencv-python omegaconf
35
+
36
+ # Set home to the user's home directory
37
+ ENV HOME=/home/user \
38
+ PYTHONPATH=$HOME/app \
39
+ PYTHONUNBUFFERED=1 \
40
+ GRADIO_ALLOW_FLAGGING=never \
41
+ GRADIO_SERVER_NAME=0.0.0.0 \
42
+ GRADIO_THEME=huggingface \
43
+ SYSTEM=spaces
44
+ # Set the working directory to the user's home directory
45
+ WORKDIR $HOME/app
46
+
47
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
48
+ COPY --chown=user . $HOME/app
49
+
50
+ CMD ["./run.sh"]
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
+
7
+ conda install -n gradio-user pytorch3d=0.7.7 -c pytorch3d -c conda-forge
8
+ conda install -n gradio-user -c conda-forge open-clip-torch pytorch-lightning
9
+
10
+ # Start app.py
11
+ echo "Starting app.py..."
12
+ export OMP_NUM_THREADS=4 # default is a wrong value: 7500m
13
+ python -c "import torch; x=torch.rand(1, device='cuda'); print(x, x.device.type)"
14
+ python app.py