File size: 4,242 Bytes
cbbde4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
so#!/usr/bin/env python3
"""
Setup script to create a virtual environment and install dependencies for the Prerad project.
This script creates a venv at the project path and installs all necessary packages.
"""

import os
import sys
import subprocess
import venv
from pathlib import Path

def main():
    # Define paths
    project_path = Path("/run/media/dheena/Leave you files/prerad")
    venv_path = project_path / "venv"
    
    print(f"πŸš€ Setting up Prerad project environment")
    print(f"πŸ“ Project path: {project_path}")
    print(f"πŸ“¦ Virtual environment path: {venv_path}")
    print()
    
    # Step 1: Create virtual environment
    print("Step 1: Creating virtual environment...")
    try:
        venv.create(venv_path, with_pip=True)
        print(f"βœ… Virtual environment created at {venv_path}")
    except Exception as e:
        print(f"❌ Error creating virtual environment: {e}")
        sys.exit(1)
    
    # Step 2: Determine pip executable path
    if sys.platform == "win32":
        pip_exe = venv_path / "Scripts" / "pip.exe"
        python_exe = venv_path / "Scripts" / "python.exe"
    else:
        pip_exe = venv_path / "bin" / "pip"
        python_exe = venv_path / "bin" / "python"
    
    print()
    print("Step 2: Upgrading pip...")
    try:
        subprocess.check_call([str(pip_exe), "install", "--upgrade", "pip"])
        print("βœ… Pip upgraded successfully")
    except Exception as e:
        print(f"❌ Error upgrading pip: {e}")
        sys.exit(1)
    
    # Step 3: Install requirements for Streamlit (UI application)
    print()
    print("Step 3: Installing Streamlit and dependencies...")
    streamlit_requirements = [
        "streamlit>=1.28.0",
        "transformers>=4.36.0",
        "pillow>=10.0.0",
        "torch>=2.0.0",  # CPU-only PyTorch
    ]
    
    # Install torch from CPU index first
    print("  - Installing PyTorch (CPU version)...")
    try:
        subprocess.check_call([
            str(pip_exe), "install", 
            "--index-url", "https://download.pytorch.org/whl/cpu",
            "torch>=2.0.0"
        ])
        print("  βœ… PyTorch installed")
    except Exception as e:
        print(f"  ⚠️  Warning installing PyTorch: {e}")
    
    # Install other streamlit packages
    print("  - Installing other packages...")
    try:
        subprocess.check_call([str(pip_exe), "install"] + streamlit_requirements[:-1])
        print("βœ… Streamlit and dependencies installed")
    except Exception as e:
        print(f"❌ Error installing Streamlit dependencies: {e}")
        sys.exit(1)
    
    # Step 4: Install ETL dependencies
    print()
    print("Step 4: Installing ETL dependencies...")
    etl_requirements = [
        "jsonlines>=4.0.0",
        "pandas>=2.0.0",
    ]
    try:
        subprocess.check_call([str(pip_exe), "install"] + etl_requirements)
        print("βœ… ETL dependencies installed")
    except Exception as e:
        print(f"❌ Error installing ETL dependencies: {e}")
        sys.exit(1)
    
    # Step 5: Install Jupyter
    print()
    print("Step 5: Installing Jupyter...")
    try:
        subprocess.check_call([str(pip_exe), "install", "jupyter>=1.0.0"])
        print("βœ… Jupyter installed")
    except Exception as e:
        print(f"❌ Error installing Jupyter: {e}")
        sys.exit(1)
    
    # Step 6: Create activation scripts info
    print()
    print("=" * 60)
    print("βœ… Setup Complete!")
    print("=" * 60)
    print()
    print("πŸ“Œ To activate the virtual environment, run:")
    print()
    if sys.platform == "win32":
        print(f"   {venv_path}\\Scripts\\activate")
    else:
        print(f"   source {venv_path}/bin/activate")
    print()
    print("πŸš€ To start the Streamlit application after activation:")
    print(f"   streamlit run {project_path}/containers/streamlit/app.py")
    print()
    print("πŸ““ To start Jupyter Notebook after activation:")
    print(f"   jupyter notebook --notebook-dir={project_path}/volumes/notebooks")
    print()
    print("πŸ”§ Or use Docker Compose for containerized services:")
    print(f"   cd {project_path}")
    print("   sudo docker compose up -d jupyter streamlit")
    print()

if __name__ == "__main__":
    main()