-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make demo app deploy-able to Hugging Face spaces (#685)
- Loading branch information
1 parent
a1fb295
commit 3038352
Showing
4 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM python:3.10.14-bullseye | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
# General dependencies | ||
locales \ | ||
locales-all && \ | ||
# Clean local repository of package files since they won't be needed anymore. | ||
# Make sure this line is called after all apt-get update/install commands have | ||
# run. | ||
apt-get clean && \ | ||
# Also delete the index files which we also don't need anymore. | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ENV LC_ALL en_US.UTF-8 | ||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US.UTF-8 | ||
|
||
# Install dependencies | ||
COPY requirements.txt . | ||
RUN pip install -r requirements.txt | ||
|
||
# Create non-root user | ||
RUN groupadd -g 900 mesop && useradd -u 900 -s /bin/bash -g mesop mesop | ||
USER mesop | ||
|
||
# Add app code here | ||
COPY . /srv/mesop-app | ||
WORKDIR /srv/mesop-app | ||
|
||
# Run Mesop through gunicorn. Should be available at localhost:8080 | ||
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "main:me"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
error_handler() { | ||
echo "Error: An error occurred. Exiting script." | ||
exit 1 | ||
} | ||
|
||
# Set up error handling | ||
trap error_handler ERR | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "Error: Please provide a destination path as an argument." | ||
exit 1 | ||
fi | ||
|
||
DEST_PATH="$1" | ||
|
||
if [ ! -d "$DEST_PATH" ]; then | ||
echo "Destination path does not exist. Creating it now." | ||
mkdir -p "$DEST_PATH" | ||
fi | ||
|
||
# Get the path of this script which is the demo dir. | ||
DEMO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
cp -R "$DEMO_DIR/" "$DEST_PATH" | ||
echo "Demo files have been copied to $DEST_PATH" | ||
|
||
cd "$DEST_PATH" | ||
echo "Changed directory to $DEST_PATH" | ||
|
||
echo "Updating allowed iframe parents to include hugging face spaces site..." | ||
# Find all .py files and update the allowed_iframe_parents list | ||
find . -name "*.py" -type f | while read -r file; do | ||
# Use sed with -i.bak so it woroks on MacOs | ||
sed -i.bak 's/allowed_iframe_parents=\["https:\/\/google\.github\.io"\]/allowed_iframe_parents=["https:\/\/google.github.io", "https:\/\/huggingface.co"]/' "$file" | ||
# Remove the backup file created by sed | ||
rm "${file}.bak" | ||
done | ||
echo "Update complete." | ||
|
||
git init | ||
|
||
git add . | ||
|
||
git commit -m "Commit" | ||
|
||
# The hf remote may already exist if the script has been run | ||
# on this dest directory before. | ||
git remote add hf https://huggingface.co/spaces/wwwillchen/mesop || true | ||
|
||
git push hf --force | ||
|
||
echo "Pushed to: https://huggingface.co/spaces/wwwillchen/mesop. Check the logs to see that it's deployed correctly." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mesop | ||
mesop>=0.10.0 | ||
Flask==3.0.0 | ||
gunicorn==22.0.0 | ||
Werkzeug==3.0.1 | ||
|