blob: c6717d111939488ee2f4b8478be25330e102e85e [file] [log] [blame]
Marc Kupietz86044852025-11-29 10:19:03 +01001#!/usr/bin/env python3
2"""
3Download spaCy model with progress bar
4"""
5import sys
6import subprocess
7import re
8
9def main():
10 if len(sys.argv) < 2:
11 print("Usage: download_with_progress.py MODEL_NAME")
12 sys.exit(1)
13
14 model_name = sys.argv[1]
15
16 print(f"Downloading {model_name}...", file=sys.stderr)
Marc Kupietz624b9c52025-11-29 11:09:08 +010017 print("This may take several minutes depending on model size", file=sys.stderr)
Marc Kupietz86044852025-11-29 10:19:03 +010018 print("", file=sys.stderr)
19
20 # Run spacy download with unbuffered output
21 process = subprocess.Popen(
22 [sys.executable, "-u", "-m", "spacy", "download", model_name, "--no-cache-dir"],
23 stdout=subprocess.PIPE,
24 stderr=subprocess.STDOUT,
25 universal_newlines=True,
26 bufsize=1
27 )
28
29 download_started = False
30
31 for line in iter(process.stdout.readline, ''):
32 if not line:
33 break
34
35 # Print the line
36 print(line.rstrip(), file=sys.stderr)
37
38 # Detect download progress
39 if 'Downloading' in line and not download_started:
40 download_started = True
41 print("Download in progress...", file=sys.stderr)
42
43 # Look for percentage or size indicators
44 if '%' in line or 'MB' in line or 'KB' in line:
45 # Extract and show progress
46 match = re.search(r'(\d+)%', line)
47 if match:
48 percent = match.group(1)
49 bar_length = 40
50 filled = int(bar_length * int(percent) / 100)
51 bar = 'ā–ˆ' * filled + 'ā–‘' * (bar_length - filled)
52 print(f"\rProgress: [{bar}] {percent}%", end='', file=sys.stderr)
53
54 process.stdout.close()
55 return_code = process.wait()
56
57 if return_code != 0:
58 print(f"\nError: Download failed with code {return_code}", file=sys.stderr)
59 sys.exit(return_code)
60
61 print("\nāœ“ Download complete!", file=sys.stderr)
62 return 0
63
64if __name__ == "__main__":
65 sys.exit(main())