-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Containerize Sitelen Pona Writing Practice app
- Create Dockerfile to build the application image - Add entrypoint script for Docker container - Add script to ensure model is downloaded - Add .dockerignore to exclude unnecessary files from Docker image - Add Streamlit configuration file - Update README with Docker setup instructions #28
- Loading branch information
1 parent
9431a45
commit 2131bce
Showing
6 changed files
with
171 additions
and
19 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,51 @@ | ||
# Git | ||
.git | ||
.gitignore | ||
|
||
# Python | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
*.so | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# Virtual Environment | ||
venv/ | ||
ENV/ | ||
.venv/ | ||
|
||
# Environment Variables | ||
.env | ||
|
||
# IDE and Development Tools | ||
.idea/ | ||
.vscode/ | ||
*.swp | ||
*.swo | ||
.ruff_cache/ | ||
.pytest_cache/ | ||
.python-version | ||
.DS_Store | ||
uv.lock | ||
|
||
# Docker | ||
Dockerfile | ||
.dockerignore | ||
|
||
# Tests | ||
tests/ |
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,8 @@ | ||
[global] | ||
disableWidgetStateDuplicationWarning = true | ||
|
||
[server] | ||
maxUploadSize = 20 | ||
|
||
[browser] | ||
gatherUsageStats = false |
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,36 @@ | ||
# Use Python 3.11 as base image | ||
FROM python:3.11-slim | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Install system dependencies required for OpenCV and other packages | ||
RUN apt-get update && apt-get install -y \ | ||
libgl1-mesa-glx \ | ||
libglib2.0-0 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy requirements file | ||
COPY requirements.txt . | ||
|
||
# Install Python dependencies | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Copy the application code and other necessary files | ||
COPY . . | ||
|
||
# Make the entrypoint script executable | ||
RUN chmod +x scripts/docker_entrypoint.sh | ||
|
||
# Create directories for models and templates if they don't exist | ||
RUN mkdir -p models templates | ||
|
||
# Expose the port Streamlit runs on | ||
EXPOSE 8501 | ||
|
||
# Set environment variables for Streamlit | ||
ENV STREAMLIT_SERVER_PORT=8501 | ||
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0 | ||
|
||
# Use the entrypoint script | ||
ENTRYPOINT ["./scripts/docker_entrypoint.sh"] |
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,8 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# First ensure the model exists | ||
python scripts/ensure_model.py | ||
|
||
# Then run the Streamlit app | ||
exec streamlit run app.py |
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,26 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
from pathlib import Path | ||
import urllib.request | ||
|
||
def download_model(model_path: str, model_url: str): | ||
"""Download the model if it doesn't exist.""" | ||
if not os.path.exists(model_path): | ||
print(f"Downloading model to {model_path}...") | ||
os.makedirs(os.path.dirname(model_path), exist_ok=True) | ||
urllib.request.urlretrieve(model_url, model_path) | ||
print("Model downloaded successfully!") | ||
else: | ||
print(f"Model already exists at {model_path}") | ||
|
||
def main(): | ||
# MediaPipe model URLs and paths | ||
models = { | ||
"models/mobilenet_v3_small.tflite": "https://storage.googleapis.com/mediapipe-models/image_embedder/mobilenet_v3_small/float32/1/mobilenet_v3_small.tflite", | ||
} | ||
|
||
for model_path, model_url in models.items(): | ||
download_model(model_path, model_url) | ||
|
||
if __name__ == "__main__": | ||
main() |