dlsmallw commited on
Commit
0637402
Β·
1 Parent(s): cfb32a4

Task-311 Update setup.sh to be easier to use.

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. setup.sh +168 -6
app.py CHANGED
@@ -331,7 +331,7 @@ with tab2:
331
  * **<a href="https://github.com/dlsmallw/NLPinitiative" style="text-decoration:none"><img src="https://raw.githubusercontent.com/tandpfun/skill-icons/refs/heads/main/icons/Github-Dark.svg" style="margin-right: 3px;" width="20" height="20"/> NLPinitiative GitHub Project</a>** - The training/evaluation pipeline used for fine-tuning the models.
332
  * **<a href="https://huggingface.co/{BIN_REPO}" style="text-decoration:none">πŸ€— NLPinitiative HF Binary Classification Model Repository</a>** - The Hugging Face hosted Binary Classification Model Repository.
333
  * **<a href="https://huggingface.co/{ML_REPO}" style="text-decoration:none">πŸ€— NLPinitiative HF Multilabel Regression Model Repository</a>** - The Hugging Face hosted Multilabel Regression Model Repository.
334
- * **<a href="https://huggingface.co/{DATASET_REPO}" style="text-decoration:none">πŸ€— NLPinitiative HF Dataset Repository</a>** - The Hugging Face hosted Dataset Repository.
335
 
336
  <hr style="margin: 0 0 0.5em 0;">
337
 
 
331
  * **<a href="https://github.com/dlsmallw/NLPinitiative" style="text-decoration:none"><img src="https://raw.githubusercontent.com/tandpfun/skill-icons/refs/heads/main/icons/Github-Dark.svg" style="margin-right: 3px;" width="20" height="20"/> NLPinitiative GitHub Project</a>** - The training/evaluation pipeline used for fine-tuning the models.
332
  * **<a href="https://huggingface.co/{BIN_REPO}" style="text-decoration:none">πŸ€— NLPinitiative HF Binary Classification Model Repository</a>** - The Hugging Face hosted Binary Classification Model Repository.
333
  * **<a href="https://huggingface.co/{ML_REPO}" style="text-decoration:none">πŸ€— NLPinitiative HF Multilabel Regression Model Repository</a>** - The Hugging Face hosted Multilabel Regression Model Repository.
334
+ * **<a href="https://huggingface.co/datasets/{DATASET_REPO}" style="text-decoration:none">πŸ€— NLPinitiative HF Dataset Repository</a>** - The Hugging Face hosted Dataset Repository.
335
 
336
  <hr style="margin: 0 0 0.5em 0;">
337
 
setup.sh CHANGED
@@ -1,41 +1,143 @@
1
  #!/usr/bin/bash
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  build() {
 
 
 
4
  clean
5
 
 
6
  python -m venv .venv
 
 
7
  source .venv/Scripts/activate
 
 
8
  pip install pipenv
9
  pipenv install
 
 
10
  }
11
 
 
 
 
12
  clean() {
 
 
 
13
  if [ -n "$VIRTUAL_ENV" ]; then
 
14
  deactivate
 
15
  fi
16
 
17
  if [ -d ./.venv ]; then
 
18
  rm -rf ./.venv
 
19
  fi
20
 
 
21
  find . -type f -name "*.py[co]" -delete
22
  find . -type d -name "__pycache__" -delete
23
- }
24
 
25
- requirements() {
26
- pipenv requirements > requirements.txt
27
  }
28
 
 
 
 
29
  docs() {
 
 
30
  case $1 in
31
  build)
 
32
  mkdocs build
 
33
  ;;
34
  serve)
 
35
  mkdocs serve
36
  ;;
37
  deploy)
 
38
  mkdocs gh-deploy --force
 
39
  ;;
40
  *)
41
  log_error "Specify 'build', 'serve' or 'deploy'. For example: docs build"
@@ -43,9 +145,25 @@ docs() {
43
  esac
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  set() {
 
 
47
  if [[ $# -lt 2 ]]; then
48
- echo "Command Requires Two Arguments."
49
  else
50
  case $1 in
51
  bin_repo)
@@ -58,19 +176,63 @@ set() {
58
  python ./scripts/config.py -d "$2"
59
  ;;
60
  *)
61
- log_error "Specify 'bin_repo', 'ml_repo' or 'ds_repo'. For example: set bin_repo <repo id>"
 
 
 
 
62
  ;;
63
  esac
64
  fi
65
  }
66
 
 
 
 
67
  run() {
68
  case $1 in
69
  dev)
 
70
  streamlit run app.py
71
  ;;
72
  *)
73
  log_error "Specify 'dev'. For example: run dev"
74
  ;;
75
  esac
76
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/usr/bin/bash
2
 
3
+ # =======================
4
+ # === Color Loggers ===
5
+ # =======================
6
+ GREEN='\033[1;32m'; YELLOW='\033[1;33m'; RED='\033[1;31m'; BLUE='\033[1;34m'; CYAN='\033[1;36m'; NC='\033[0m'
7
+
8
+ log_info() { echo -e "${GREEN}[INFO] $1${NC}"; }
9
+ log_warn() { echo -e "${YELLOW}[WARN] $1${NC}"; }
10
+ log_error() { echo -e "${RED}[ERROR] $1${NC}"; }
11
+ log_help() { echo -e "${CYAN}$1${NC}"; }
12
+
13
+ # =========================
14
+ # === Sourced-Only Check ==
15
+ # =========================
16
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
17
+ log_error "Please source this script instead of running it directly:"
18
+ echo " source ./scripts/setup.sh"
19
+ exit 1
20
+ fi
21
+
22
+ # ======================
23
+ # === Project Paths ===
24
+ # ======================
25
+ ROOT="$( cd "$( dirname "${BASH_SOURCE[1]}" )/.." && pwd )"
26
+ PROJECT_ROOT="$ROOT/NLPinitiative-Streamlit-App"
27
+
28
+ # ================================
29
+ # === Python Version Check ===
30
+ # ================================
31
+ check_python_version() {
32
+ REQUIRED="3.7"
33
+ if ! command -v python3 &> /dev/null; then
34
+ log_warn "python3 not found. Python >= 3.7 is recommended if you need Python tasks."
35
+ else
36
+ local PY_VER
37
+ PY_VER=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
38
+ if [[ $(printf '%s\n' "$REQUIRED" "$PY_VER" | sort -V | head -n1) != "$REQUIRED" ]]; then
39
+ log_warn "Detected Python version: $PY_VER (older than $REQUIRED). Consider upgrading."
40
+ else
41
+ log_info "Detected Python version: $PY_VER"
42
+ fi
43
+ fi
44
+ }
45
+
46
+ # =================================
47
+ # === pipenv Check (No Prompt) ===
48
+ # =================================
49
+ check_pipenv() {
50
+ if ! command -v pipenv &> /dev/null; then
51
+ log_warn "pipenv not found. Install via 'pip install pipenv'."
52
+ else
53
+ log_info "Detected pipenv."
54
+ fi
55
+ }
56
+
57
+ # =======================================
58
+ # === Virtual Env Existence Check ===
59
+ # =======================================
60
+ check_virtualenv() {
61
+ cd "$PROJECT_ROOT" || return 1
62
+
63
+ if [ -d ./.venv ]; then
64
+ log_info "Local .venv found. Activating venv..."
65
+ source .venv/Scripts/activate
66
+ log_info "Virtual Environment Activated."
67
+ else
68
+ log_warn "No local .venv found. Run 'build' to create and activate a local venv."
69
+ fi
70
+ }
71
+
72
+ # ============================
73
+ # === Build Function ===
74
+ # ============================
75
  build() {
76
+ cd "$PROJECT_ROOT" || return 1
77
+ log_info "Running 'build': Cleaning project and then rebuilding virtual environment..."
78
+
79
  clean
80
 
81
+ log_info "Setting up new Virtual Environment..."
82
  python -m venv .venv
83
+
84
+ log_info "Activating Virtual Environment..."
85
  source .venv/Scripts/activate
86
+
87
+ log_info "Loading dependencies..."
88
  pip install pipenv
89
  pipenv install
90
+
91
+ log_info "Build Complete."
92
  }
93
 
94
+ # ========================
95
+ # === Clean Function ===
96
+ # ========================
97
  clean() {
98
+ cd "$PROJECT_ROOT" || return 1
99
+ log_info "Running 'clean': Removing .venv and any python cache and compiled binary files."
100
+
101
  if [ -n "$VIRTUAL_ENV" ]; then
102
+ log_info "Deactivating Virtual Environment..."
103
  deactivate
104
+ log_info "Virtual Environment Deactivated."
105
  fi
106
 
107
  if [ -d ./.venv ]; then
108
+ log_info "Removing .venv directory..."
109
  rm -rf ./.venv
110
+ log_info "Removed .venv directory."
111
  fi
112
 
113
+ log_info "Removing cache and compiled binary files..."
114
  find . -type f -name "*.py[co]" -delete
115
  find . -type d -name "__pycache__" -delete
116
+ log_info "Cache and compiled binary files removed."
117
 
118
+ log_info "Clean Complete."
 
119
  }
120
 
121
+ # ============================
122
+ # === Generate Docs Command ==
123
+ # ============================
124
  docs() {
125
+ cd "$PROJECT_ROOT" || return 1
126
+
127
  case $1 in
128
  build)
129
+ log_info "Building documentation..."
130
  mkdocs build
131
+ log_info "Documentation built."
132
  ;;
133
  serve)
134
+ log_info "Serving documentation..."
135
  mkdocs serve
136
  ;;
137
  deploy)
138
+ log_info "Deploying documentation to GH Pages..."
139
  mkdocs gh-deploy --force
140
+ log_info "Documentation deployed to GH Pages."
141
  ;;
142
  *)
143
  log_error "Specify 'build', 'serve' or 'deploy'. For example: docs build"
 
145
  esac
146
  }
147
 
148
+ # ============================
149
+ # === Generate Requirements ==
150
+ # ============================
151
+ requirements() {
152
+ cd "$PROJECT_ROOT" || return 1
153
+
154
+ log_info "Generating requirements.txt..."
155
+ pipenv requirements > requirements.txt
156
+ log_info "requirements.txt file generated."
157
+ }
158
+
159
+ # ============================
160
+ # === Config Settings ===
161
+ # ============================
162
  set() {
163
+ cd "$PROJECT_ROOT" || return 1
164
+
165
  if [[ $# -lt 2 ]]; then
166
+ log_error "Set Command Requires Two Arguments."
167
  else
168
  case $1 in
169
  bin_repo)
 
176
  python ./scripts/config.py -d "$2"
177
  ;;
178
  *)
179
+ log_error "Invalid set option."
180
+ echo "Available 'set' options:"
181
+ echo " bin_repo <repo ID> - Sets the binary model's repo ID in the pyproject.toml file."
182
+ echo " ml_repo <repo ID> - Sets the multilabel model's repo ID in the pyproject.toml file."
183
+ echo " ds_repo <repo ID> - Sets the dataset repo ID in the pyproject.toml file."
184
  ;;
185
  esac
186
  fi
187
  }
188
 
189
+ # ============================
190
+ # === Running the App ===
191
+ # ============================
192
  run() {
193
  case $1 in
194
  dev)
195
+ log_info "Running the Streamlit app in a local dev environment..."
196
  streamlit run app.py
197
  ;;
198
  *)
199
  log_error "Specify 'dev'. For example: run dev"
200
  ;;
201
  esac
202
+ }
203
+
204
+ # ============================
205
+ # === Help Command ===
206
+ # ============================
207
+ help() {
208
+ cd "$PROJECT_ROOT" || return 1
209
+
210
+ log_help "Usage: source ./scripts/setup.sh"
211
+ echo "Available commands:"
212
+ echo " Miscellaneous commands:"
213
+ echo " help - Show this help message."
214
+ echo "==========================================="
215
+ echo " Project Building, Cleaning, etc. commands:"
216
+ echo " build - Cleans and reinstalls Python dependencies."
217
+ echo " clean - Cleans project (i.e., deactivates venv, removes .venv and clears project of python cache and binary files)."
218
+ echo " run dev - Runs the application in a local dev environment."
219
+ echo "==========================================="
220
+ echo " 'docs' command options:"
221
+ echo " docs build - Generates mkdocs for the project."
222
+ echo " docs serve - Serves documentation locally."
223
+ echo " docs deploy - Deploys documentation to associated GH Pages."
224
+ echo "==========================================="
225
+ echo " 'set' command options:"
226
+ echo " set bin_repo <repo ID> - Sets the binary model's repo ID in the pyproject.toml file."
227
+ echo " set ml_repo <repo ID> - Sets the multilabel model's repo ID in the pyproject.toml file."
228
+ echo " set ds_repo <repo ID> - Sets the dataset repo ID in the pyproject.toml file."
229
+ }
230
+
231
+ log_info "Loading setup.sh script..."
232
+
233
+ check_python_version
234
+ check_pipenv
235
+ check_virtualenv
236
+
237
+ log_info "setup.sh loaded. Type 'help' for usage."
238
+ log_info "Try 'build' then 'run dev' to get started."