jingyangcarl commited on
Commit
1817656
Β·
1 Parent(s): 0874c06
Files changed (5) hide show
  1. Dockerfile +50 -0
  2. README.md +4 -4
  3. app.py +17 -0
  4. environment.yml +7 -0
  5. run.sh +16 -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
+
22
+ # Set the environment variable to use the gradio environment by default
23
+ RUN echo "source activate gradio" > ~/.bashrc
24
+ ENV PATH /opt/conda/envs/gradio/bin:$PATH
25
+
26
+ # Set up a new user named "user" with user ID 1000
27
+ RUN useradd -m -u 1000 user
28
+ # Switch to the "user" user
29
+ USER user
30
+
31
+ RUN conda create -n gradio-user python=3.11
32
+ RUN conda run -n gradio-user pip install --upgrade pip
33
+ RUN conda run -n gradio-user pip install diffusers["torch"] transformers accelerate xformers
34
+ RUN conda run -n gradio-user pip install gradio
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"]
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Docker Test17
3
- emoji: 🐠
4
- colorFrom: red
5
- colorTo: blue
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,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Kill existing app.py process if running
8
+ # if pgrep -f "python app.py" > /dev/null; then
9
+ # echo "Stopping existing app.py..."
10
+ # pkill -f "python app.py"
11
+ # sleep 2 # Small delay to ensure it stops
12
+ # fi
13
+
14
+ # Start app.py
15
+ echo "Starting app.py..."
16
+ python app.py