jingyangcarl commited on
Commit
40b98a2
Β·
1 Parent(s): e31c6cb
Files changed (5) hide show
  1. Dockerfile +38 -0
  2. README.md +3 -3
  3. app.py +17 -0
  4. environment.yml +7 -0
  5. run.sh +34 -0
Dockerfile ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ RUN conda run -n gradio pip install --upgrade pip
11
+ RUN conda run -n gradio diffusers["torch"] transformers accelerate xformers
12
+ RUN conda run -n gradio pip install gradio
13
+
14
+ # Set the environment variable to use the gradio environment by default
15
+ RUN echo "source activate gradio" > ~/.bashrc
16
+ ENV PATH /opt/conda/envs/gradio/bin:$PATH
17
+
18
+ # Set up a new user named "user" with user ID 1000
19
+ RUN useradd -m -u 1000 user
20
+ # Switch to the "user" user
21
+ USER user
22
+ # Set home to the user's home directory
23
+ ENV HOME=/home/user \
24
+ PYTHONPATH=$HOME/app \
25
+ PYTHONUNBUFFERED=1 \
26
+ GRADIO_ALLOW_FLAGGING=never \
27
+ GRADIO_NUM_PORTS=1 \
28
+ GRADIO_SERVER_NAME=0.0.0.0 \
29
+ GRADIO_THEME=huggingface \
30
+ SYSTEM=spaces
31
+
32
+ # Set the working directory to the user's home directory
33
+ WORKDIR $HOME/app
34
+
35
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
36
+ COPY --chown=user . $HOME/app
37
+
38
+ CMD ["./run.sh"]
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Docker Test8
3
- emoji: πŸƒ
4
- colorFrom: purple
5
  colorTo: pink
6
  sdk: docker
7
  pinned: false
 
1
  ---
2
+ title: Docker Test6
3
+ emoji: πŸ‘€
4
+ colorFrom: pink
5
  colorTo: pink
6
  sdk: docker
7
  pinned: false
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,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e # stop on error
3
+
4
+ eval "$(conda shell.bash hook)"
5
+
6
+ ENV_NAME="matgen-plus"
7
+ PYTHON_VER="3.11"
8
+
9
+ # Create env and install packages only if it doesn't exist
10
+ if ! conda env list | grep -q "^${ENV_NAME}\s"; then
11
+ echo "Creating conda environment: $ENV_NAME"
12
+ conda create -y -n "$ENV_NAME" python="$PYTHON_VER"
13
+ conda activate "$ENV_NAME"
14
+
15
+ echo "Installing packages in $ENV_NAME..."
16
+
17
+ # pip installs
18
+ pip install diffusers["torch"] transformers accelerate xformers
19
+ pip install gradio controlnet-aux
20
+ pip install trimesh xatlas scikit-learn opencv-python omegaconf
21
+
22
+ # conda installs
23
+ # conda --name "$ENV_NAME" install -y pytorch3d -c pytorch -c conda-forge
24
+ # conda install -y -c conda-forge open-clip-torch pytorch-lightning
25
+
26
+ python app.py
27
+
28
+ else
29
+ echo "Conda environment '$ENV_NAME' already exists."
30
+ conda activate "$ENV_NAME"
31
+ fi
32
+
33
+ # Run the app
34
+ # python app.py