Skip to content

Commit ae272c3

Browse files
committed
adding setup and html docs
1 parent 4c240a1 commit ae272c3

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ N.B: I am constantly working to make this better, and your suggestions are inval
2929
- [ ] create pip package
3030
- [ ] add other ebook formats like epub, etc
3131
- [ ] optimise code/ reduce processing time
32+
33+
34+
## EDIT
35+
36+
1. You can optionally run 'setup.sh' if you're on MacOs or linux.
37+
2. If you're on windows, you can also run 'setup.ps1'
38+
3. The aim of these setup scripts is to ease the complexity of setting up bionicpython.

Diff for: bionicpython/bionicpython.py

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def process_document(doc_path, ratio):
4343
try:
4444
# Run the conversion script as a subprocess
4545
subprocess.run([sys.executable, 'converter.py', '--pdf', doc_path, '--docx', docx_path])
46+
47+
# Modify this command to run in the absolute path (with relation to this script) to converter.py
48+
subprocess.run([sys.executable, 'converter.py', '--pdf', doc_path, '--docx', docx_path])
49+
4650
# Replace '.pdf' with '.docx' in the file path
4751
doc_path = docx_path
4852
except subprocess.CalledProcessError as e:

Diff for: docs/index.html

Whitespace-only changes.

Diff for: setup.ps1

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Check if a command exists
2+
function Test-CommandExists {
3+
param (
4+
[string]$Command
5+
)
6+
$exists = $null -ne (Get-Command $Command -ErrorAction SilentlyContinue)
7+
return $exists
8+
}
9+
10+
# Install Python on Windows
11+
function Install-PythonWindows {
12+
Write-Host "Attempting to install Python 3.11..."
13+
# Python installation on Windows should be done manually or through an installer
14+
Write-Host "Please install Python 3.11 manually from the official website."
15+
exit
16+
}
17+
18+
# 1. Check if Python is installed
19+
if (-not (Test-CommandExists "python") -and -not (Test-CommandExists "python3")) {
20+
Write-Host "Python is not installed. Attempting to install..."
21+
Install-PythonWindows
22+
# Recheck if Python is installed
23+
if (-not (Test-CommandExists "python") -and -not (Test-CommandExists "python3")) {
24+
Write-Host "Python installation failed. Please install Python manually."
25+
exit
26+
}
27+
} else {
28+
Write-Host "Python is already installed."
29+
}
30+
31+
# 2. Check if Flutter is installed
32+
if (-not (Test-CommandExists "flutter")) {
33+
Write-Host "Warning: If you want to build the GUI, you might need Flutter (optionally)."
34+
}
35+
36+
# 3. Install requirements using pip
37+
try {
38+
pip install -r requirements.txt -ErrorAction Stop
39+
} catch {
40+
try {
41+
pip3 install -r requirements.txt -ErrorAction Stop
42+
} catch {
43+
Write-Host "Failed to install requirements with pip and pip3. Attempting to install pip..."
44+
python -m ensurepip
45+
if ($LASTEXITCODE -ne 0) {
46+
python3 -m ensurepip
47+
}
48+
if ($LASTEXITCODE -ne 0) {
49+
Write-Host "Failed to install pip. Please reinstall Python manually."
50+
exit
51+
}
52+
pip install -r requirements.txt
53+
}
54+
}
55+
56+
# 4. Download spacy model
57+
try {
58+
python -m spacy download en_core_web_sm -ErrorAction Stop
59+
} catch {
60+
python3 -m spacy download en_core_web_sm
61+
if ($LASTEXITCODE -ne 0) {
62+
Write-Host "Failed to download spacy model. Please check your Python installation."
63+
exit
64+
}
65+
}
66+
67+
# 5. Inform the user about the next steps
68+
Write-Host "To use the CLI, run the following command from the current directory:"
69+
Write-Host "python bionicpython/bionicpython.py '<path to your pdf/docx file>'"
70+
Write-Host "Remember to insert the path in quotes if it isn't already."

Diff for: setup.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# Function to check if command exists
4+
command_exists() {
5+
command -v "$1" >/dev/null 2>&1
6+
}
7+
8+
# Function to install Python on macOS
9+
install_python_macos() {
10+
echo "Installing Python 3.11 using Homebrew..."
11+
brew install [email protected]
12+
}
13+
14+
# Function to install Python on Linux
15+
install_python_linux() {
16+
echo "Installing Python 3.11 using apt..."
17+
sudo apt update
18+
sudo apt install python3.11 -y
19+
}
20+
21+
# 1. Check if Python is installed
22+
if ! command_exists python && ! command_exists python3; then
23+
echo "Python is not installed. Attempting to install..."
24+
if [[ "$OSTYPE" == "darwin"* ]]; then
25+
install_python_macos
26+
else
27+
install_python_linux
28+
fi
29+
# Open a new terminal to check if installation was successful
30+
if ! command_exists python && ! command_exists python3; then
31+
echo "Python installation failed. Please install Python manually."
32+
exit 1
33+
fi
34+
else
35+
echo "Python is already installed."
36+
fi
37+
38+
# 2. Check if Flutter is installed
39+
if ! command_exists flutter; then
40+
echo "Warning: If you want to build the GUI, you might need Flutter (optionally)."
41+
fi
42+
43+
# 3. Install requirements using pip
44+
open_new_terminal_and_run() {
45+
if [[ "$OSTYPE" == "darwin"* ]]; then
46+
osascript -e 'tell app "Terminal" to do script "'"$1"'"'
47+
else
48+
x-terminal-emulator -e $1
49+
fi
50+
}
51+
52+
open_new_terminal_and_run "
53+
if ! pip install -r requirements.txt && ! pip3 install -r requirements.txt; then
54+
if ! command_exists pip; then
55+
python -m ensurepip || python3 -m ensurepip
56+
fi
57+
if ! pip install -r requirements.txt && ! pip3 install -r requirements.txt; then
58+
echo 'Failed to install requirements. Please reinstall Python manually.'
59+
exit 1
60+
fi
61+
fi
62+
"
63+
64+
# 4. Download spacy model
65+
if ! python -m spacy download en_core_web_sm && ! python3 -m spacy download en_core_web_sm; then
66+
echo "Failed to download spacy model. Please check your Python installation."
67+
exit 1
68+
fi
69+
70+
# 5. Inform the user about the next steps
71+
echo "To use the CLI, run the following command from the current directory:"
72+
echo "python bionicpython/bionicpython.py '<path to your pdf/docx file>'"
73+
echo "Remember to insert the path in quotes if it isn't already."

0 commit comments

Comments
 (0)