Hosting PyHARP Apps in the Cloud (HuggingFace Spaces)
Automatically generated Gradio endpoints are only available for a maximum of 72 hours. If you'd like to keep an endpoint active and share it with other users, you can use HuggingFace Spaces (similar hosting services are also available) to host your PyHARP app indefinitely.
Gradio Endpoints
This is the most convenient solution for hosting a PyHARP app. If you are a Hugging Face PRO subscriber, you can use ZeroGPU to dynamically allocate GPU resources according to user requests without any additional charges. Non-PRO users can select from CPU environments or paid GPU options.
- Create a new HuggingFace Space.
- Choose Gradio as the SDK along with the blank template.
- Select the desired hardware option.
- Create the space and clone the initialized repository locally:
git clone https://huggingface.co/spaces/<USERNAME>/<SPACE_NAME>- Add your files to the repository, commit, then push to the
mainbranch:
git add .
git commit -m "initial commit"
git push -u origin main- Configure the following repository files:
README.mdSet sdk_version to 5.28.0, the recommended version of
gradio. HARP may not work with the very latest or earlier versions.requirements.txtPlace all of the required pip packages in this file. It should also include the latest version of
pyharp:git+https://github.com/TEAMuP-dev/pyharp.git@v0.3.0Note that you do not have to include the
gradiopackage in this file.packages.txtPlace any necessary apt-get install debian packages in this file. Some models may require these.
Docker Endpoints
Some models may have been developed with older versions of Python, and attempting to deploy them would lead to dependency issues. For example, the numpy.float and numpy.int deprecation in numpy==1.24 breaks older packages such as madmom. Therefore, we may need to patch any corresponding source files during the deployment process. However, this is not supported by the highly-modularized Gradio SDK.
Using Docker endpoints can help circumvent these issues. Docker will allow you to customize the deployment, which makes room for any necessary patches. Note however that ZeroGPU is not available for Docker spaces, meaning you must pay to use GPU resources with this option.
- Create a new HuggingFace Space.
- Choose Docker as the SDK along with the blank template.
- Select the desired hardware option.
- Create the space and clone the initialized repository locally:
git clone https://huggingface.co/spaces/<USERNAME>/<SPACE_NAME>- Add your files to the repository, commit, then push to the
mainbranch:
git add .
git commit -m "initial commit"
git push -u origin main- Configure the following repository files:
README.mdSet app_port to any valid
<PORT>.requirements.txtPlace all of the required pip packages in this file. It should also include the recommended version of
gradioand the latest version ofpyharp:gradio==5.28.0 git+https://github.com/TEAMuP-dev/pyharp.git@v0.3.0packages.txtPlace any necessary apt-get install debian packages in this file. Some models may require these.
DockerfileInstalls the required pip and apt-get packages, and supports manual patching (e.g. of
madmomin the following example):DockerFROM python:3.10-slim # Set python version WORKDIR /app COPY packages.txt /app/packages.txt # System dependencies for building packages from source RUN apt-get update RUN xargs apt-get install -y --no-install-recommends < /app/packages.txt RUN rm -rf /var/lib/apt/lists/* COPY requirements.txt /app/requirements.txt # Disable build isolation so Cython installed in the environment is visible at build time ENV PIP_NO_BUILD_ISOLATION=1 RUN pip install --no-cache-dir -U pip wheel Cython RUN pip install --no-cache-dir setuptools==80.9.0 RUN pip install --no-cache-dir -r /app/requirements.txt RUN pip install --no-cache-dir --no-build-isolation madmom # Patch madmom package COPY patch_madmom.py /app/scripts/patch_madmom.py # Script to patch madmom source files RUN python /app/scripts/patch_madmom.py RUN python -c "import madmom; print('madmom import OK')" # Copy remainder of the repo COPY . /app # HF Spaces route traffic to <PORT> # Gradio should listen accordingly ENV PORT=<PORT> # <PORT> in README.md EXPOSE <PORT> # Run the app CMD ["python", "app.py"]
Here are a few tips and best practices when dealing with HuggingFace Spaces:
- Spaces operate based off of the files in the
mainbranch - An access token may be required to push commits to HuggingFace Spaces
- A
.gitignorefile should be added to maintain repository orderliness (e.g., to ignoresrc/_outputs) - Pin versions for
numpy(e.g.,<2),torch(e.g.,==2.2.2), andtorchaudio(e.g.,==2.2.2) to avoid unexpected build issues caused by the latest versions of these packages
For more information, please refer to the offical document from Hugging Face about Spaces.
Accessing Within HARP
PyHARP apps deployed to HuggingFace will begin running at https://huggingface.co/spaces/<USERNAME>/<SPACE_NAME>. The shorthand <USERNAME>/<SPACE_NAME> can also be used within HARP to reference the endpoint. The two deployment methods above produce identical UIs and functionality.