Last active
May 27, 2025 23:32
-
-
Save adrianseeley/90bf1899e61dec07bdd68dc40ef5f54f to your computer and use it in GitHub Desktop.
converter-startup
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euo pipefail | |
# This script installs dependencies, sets up a venv, | |
# downloads and configures magic-pdf & server, and | |
# installs+starts uvicorn as a systemd service. | |
# 1. Install OS packages | |
echo "Updating package index and installing OS dependencies..." | |
sudo apt update -qq | |
sudo DEBIAN_FRONTEND=noninteractive apt install -y \ | |
build-essential cmake pkg-config git ninja-build gdb clang \ | |
autoconf automake libtool flex bison valgrind ccache \ | |
python-is-python3 jq wget lsof | |
# 2. Create Python virtual environment | |
echo "Creating Python venv at ~/myenv..." | |
python3 -m venv "$HOME/myenv" | |
# shellcheck source=/dev/null | |
source "$HOME/myenv/bin/activate" | |
# 3. Install Python packages | |
echo "Upgrading pip and installing Python dependencies..." | |
pip install --upgrade pip | |
pip install "magic-pdf[full]" fastapi uvicorn typing_extensions \ | |
python-multipart pydantic torch torchvision python-socketio | |
# 4. Download and prepare MinerU models | |
echo "Downloading MinerU model installer..." | |
wget https://github.com/opendatalab/MinerU/raw/master/scripts/download_models_hf.py \ | |
-O download_models_hf.py | |
python download_models_hf.py | |
# 5. Configure magic-pdf settings | |
echo "Configuring /root/magic-pdf.json..." | |
sudo jq '.["device-mode"] = "cuda" | .["table-config"].enable = false | .["formula-config"].enable = false' /root/magic-pdf.json > /tmp/magic-pdf.json.tmp | |
sudo mv /tmp/magic-pdf.json.tmp /root/magic-pdf.json | |
# 6. Download your FastAPI server code | |
echo "Fetching server.py..." | |
wget https://gist.githubusercontent.com/adrianseeley/6825c1efd56467147eb759c6445e784b/raw/3b7042817bdb9d68c9b8fa41a171acb907cd7046/server.py \ | |
-O server.py | |
# 7. Kill any existing process on port 8080 | |
echo "Stopping processes on port 8080 (if any)..." | |
sudo kill -9 "$(lsof -t -iTCP:8080 -sTCP:LISTEN)" || true | |
# Start the FastAPI server with uvicorn | |
echo "Starting FastAPI server with uvicorn..." | |
tmux new-session -d -s api "uvicorn server:app --host 0.0.0.0 --port 8080" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment