forked from UKZN-GroupProjs/Python-Code-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
39 lines (31 loc) · 1.25 KB
/
run.py
File metadata and controls
39 lines (31 loc) · 1.25 KB
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
import os
import sys
import platform
import subprocess
def main():
venv_dir = os.path.join(os.getcwd(), "venv")
# Determine the Python executable inside the venv based on OS
if platform.system() == "Windows":
python_exe = os.path.join(venv_dir, "Scripts", "python.exe")
else:
python_exe = os.path.join(venv_dir, "bin", "python")
# Step 1: Create venv if it doesn't exist
if not os.path.exists(python_exe):
print("⚙️ Creating virtual environment...")
subprocess.check_call([sys.executable, "-m", "venv", venv_dir])
# Step 2: Upgrade pip and install dependencies
print("📦 Installing dependencies...")
subprocess.check_call([python_exe, "-m", "pip", "install", "--upgrade", "pip"])
subprocess.check_call([python_exe, "-m", "pip", "install", "-r", "requirements.txt"])
# Step 3: Launch Streamlit interactively
print("🚀 Launching Streamlit app...")
if platform.system() == "Windows":
creation_flags = subprocess.CREATE_NEW_CONSOLE
else:
creation_flags = 0 # default for Linux/macOS
subprocess.Popen(
[python_exe, "-m", "streamlit", "run", "main.py"], # modular launcher
creationflags=creation_flags
)
if __name__ == "__main__":
main()