File size: 1,968 Bytes
dae60e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
#!/usr/bin/env bash
set -euo pipefail

BACKEND="${RECEIPT_BACKEND:-hf_inference}"
MODEL_DIR="${MODEL_DIR:-models}"

while [[ $# -gt 0 ]]; do
  case "$1" in
    --backend)
      BACKEND="$2"
      shift 2
      ;;
    --deterministic)
      BACKEND="deterministic"
      shift
      ;;
    --llamacpp)
      BACKEND="llamacpp"
      shift
      ;;
    --modal-llm)
      BACKEND="modal_llm"
      shift
      ;;
    --hf-inference)
      BACKEND="hf_inference"
      shift
      ;;
    --model-dir)
      MODEL_DIR="$2"
      shift 2
      ;;
    -h|--help)
      cat <<'EOF'
Usage: scripts/dev.sh [--backend hf_inference|modal_llm|deterministic|llamacpp] [--model-dir models]

Local staged entrypoint:
  --backend hf_inference   Start Gradio against HF Inference API
  --backend modal_llm      Start Gradio against Modal receipt parser endpoint
  --backend deterministic  Start only Gradio with rule-based parsing
  --backend llamacpp       Download/start local llama.cpp servers, then Gradio

Examples:
  scripts/dev.sh --hf-inference
  scripts/dev.sh --modal-llm
  scripts/dev.sh --deterministic
  scripts/dev.sh --llamacpp
EOF
      exit 0
      ;;
    *)
      echo "Unknown argument: $1" >&2
      exit 2
      ;;
  esac
done

case "$BACKEND" in
  hf_inference)
    exec scripts/run_app.sh --backend hf_inference
    ;;
  deterministic)
    exec scripts/run_app.sh --backend deterministic
    ;;
  modal_llm)
    exec scripts/run_app.sh --backend modal_llm
    ;;
  llamacpp)
    export MODEL_DIR
    scripts/start_llamacpp.sh --model-dir "$MODEL_DIR" &
    SERVER_PID=$!

    cleanup() {
      kill "$SERVER_PID" 2>/dev/null || true
      wait "$SERVER_PID" 2>/dev/null || true
    }
    trap cleanup EXIT INT TERM

    echo "Waiting for llama.cpp servers to bind..."
    sleep 15
    scripts/run_app.sh --backend llamacpp
    ;;
  *)
    echo "Invalid backend: $BACKEND. Expected hf_inference, deterministic, llamacpp, or modal_llm." >&2
    exit 2
    ;;
esac