File size: 3,047 Bytes
3835cb8
 
 
 
 
 
 
 
 
60232d3
 
 
 
 
 
 
 
 
 
 
3835cb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60232d3
3835cb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
# Pathify one-shot installer for an Oracle Always-Free Ubuntu VM (ARM or x86).
# Usage (on the VM):  curl -sL <this-url> | sudo bash -s -- YOUR_ACCESS_CODE
set -euo pipefail

PASSCODE="${1:-pathify123}"
APP=/opt/pathify
HF=https://huggingface.co/spaces/Shubhambhandari/Pathify

echo "[pathify] 0/5 checking memory, adding swap on small boxes..."
MEM_MB=$(free -m | awk '/^Mem:/{print $2}')
if [ "${MEM_MB:-0}" -lt 4000 ] && [ ! -f /swapfile ]; then
  echo "[pathify] low RAM (${MEM_MB}MB) -> creating 4G swap"
  fallocate -l 4G /swapfile || dd if=/dev/zero of=/swapfile bs=1M count=4096
  chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
  grep -q '/swapfile' /etc/fstab || echo '/swapfile none swap sw 0 0' >> /etc/fstab
fi
# On a small box, skip the demo cohort so boot is light.
if [ "${MEM_MB:-0}" -lt 4000 ]; then CASES=0; SLIDES=0; else CASES=24; SLIDES=3; fi

echo "[pathify] 1/5 installing system packages..."
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get install -y python3-pip python3-venv git curl iptables-persistent

echo "[pathify] 2/5 fetching the app code from Hugging Face..."
rm -rf /tmp/hf_src
git clone --depth 1 "$HF" /tmp/hf_src
mkdir -p "$APP"
cp -r /tmp/hf_src/backend /tmp/hf_src/frontend /tmp/hf_src/pathqa "$APP"/

echo "[pathify] 3/5 downloading the trained model (44 MB)..."
curl -L -o "$APP/model.pt" "$HF/resolve/main/model.pt"

echo "[pathify] 4/5 building python env + torch (several minutes)..."
python3 -m venv "$APP/venv"
"$APP/venv/bin/pip" install --upgrade pip -q
"$APP/venv/bin/pip" install -q torch torchvision pillow numpy h5py
mkdir -p "$APP/data/feedback"

echo "[pathify] 5/5 creating the service + opening the port..."
cat >/etc/systemd/system/pathify.service <<EOF
[Unit]
Description=Pathify second-reader QA
After=network.target

[Service]
WorkingDirectory=$APP
Environment=PYTHONPATH=$APP:$APP/backend
Environment=PATHQA_MODEL=$APP/model.pt
Environment=PATHQA_FEEDBACK_DIR=$APP/data/feedback
Environment=PATHQA_AUDIT_LOG=$APP/data/audit.log
Environment=PATHQA_PASSWORD=$PASSCODE
ExecStart=$APP/venv/bin/python $APP/backend/server.py --host 0.0.0.0 --port 80 --cases $CASES --slides $SLIDES --demo-train-steps 0
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
EOF

# Ubuntu on Oracle drops inbound traffic except port 22 by default; allow 80.
iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT || true
netfilter-persistent save || true

systemctl daemon-reload
systemctl enable pathify
systemctl restart pathify

IP=$(curl -s ifconfig.me || echo YOUR_VM_PUBLIC_IP)
echo "=================================================================="
echo " Pathify is starting (first boot loads the model + builds the"
echo " demo worklist, about 1-2 minutes)."
echo ""
echo "   URL:         http://$IP"
echo "   Access code: $PASSCODE"
echo ""
echo " Check status:  sudo systemctl status pathify"
echo " View logs:     sudo journalctl -u pathify -f"
echo "=================================================================="