File size: 2,525 Bytes
1322ef0 fbbb171 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
---
title: Base Dev
emoji: 🐨
colorFrom: yellow
colorTo: indigo
sdk: docker
pinned: false
license: cc0-1.0
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
# Base Docker image for development
## Purpose
This repo is used to test the creation of a base docker image that can serve as a starting image to develop webapps based on huggingface libraries. The image comes with common python dependencies installed. The purpose is to accelerate the dependencies installation for applications developed on top of this image.
## How to use this repo
### Create a repo for your web app
Start with creating a new repo for your app using your favorite git tool, i.e. local git repo, HuggingFace repo, GitHub, GitLab, etc.. In this document, we will refer to your new repo as ```$MY_WEBAPP_REPO```
### Write your app and its dependencies
Create a Dockerfile in ```$MY_WEBAPP_REPO``` that uses the docker image from this repo. Below is a sample Docker file:
```Dockerfile
FROM <--THe DOCKER IMAGE IN THIS REPO-->
RUN apt-get update && apt-get install -y python3 python3-pip
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
COPY --chown=user . $HOME/app
CMD ["python", "app.py"]
```
The above docker file uses ```requirements.txt``` file in ```$MY_WEBAPP_REPO```. Create this ```requirements.txt``` file in ```$MY_WEBAPP_REPO``` with the required packages for your project. You can find a sample [requirements.txt](requirements.txt) in this repo or use ```pip freeze > my_requirements.txt``` to generate your requirements from your current project.
Create ```app.py``` file in ```$MY_WEBAPP_REPO``` with your application. For example you can use [Building your First Demo](https://www.gradio.app/guides/quickstart#building-your-first-demo) from the Gradio Quick Start Guide.
You can run your gradio app locally for testing:
```
python app.py
```
### Build and run the docker image for your app
Building a docker image may be needed if you would like to host your app on a place like HuggingFace Spaces.
To use ```docker compose``` create ```compose.yaml``` file in ```$MY_WEBAPP_REPO```.
Alternatively one can use ```docker build``` and ```docker run`` commands. Consult docker documentation for the commands and their flags. |