Spaces:
Build error
Build error
| 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() | |