base-dev / README.md
demo
initial commit
fbbb171
metadata
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:

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 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 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.