File size: 2,191 Bytes
55159b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
import subprocess

def run_step(step_name, command_args):
    print(f"\n>>> Running: {step_name}...")
    try:
        # Run python module or script in the current environment
        result = subprocess.run(
            [sys.executable] + command_args,
            cwd=os.getcwd(),
            check=True
        )
        print(f"Success: {step_name} completed.")
        return True
    except subprocess.CalledProcessError as e:
        print(f"Error in {step_name}: {str(e)}")
        return False

def setup():
    print("=" * 60)
    print("Phi-3 Text-to-SQL Studio Setup Assistant")
    print("=" * 60)
    
    # 1. Install remaining dependencies
    print("\n>>> Checking and installing remaining python libraries...")
    libraries = [
        "transformers", 
        "peft", 
        "bitsandbytes", 
        "trl", 
        "datasets", 
        "accelerate", 
        "flask", 
        "pandas"
    ]
    
    try:
        # Run pip install inside our virtual environment
        pip_path = os.path.join(".venv", "Scripts", "pip") if os.path.exists(".venv") else "pip"
        cmd = [pip_path, "install", "-U"] + libraries
        print(f"Executing: {' '.join(cmd)}")
        subprocess.run(cmd, check=True)
        print("Success: Libraries installed successfully.")
    except Exception as e:
        print(f"Warning during library installation: {str(e)}")
        print("Please ensure your virtual environment is activated and run: pip install -r requirements.txt")

    # 2. Setup SQLite Database
    success = run_step("Database Initialization", ["src/database.py"])
    if not success:
        sys.exit(1)
        
    # 3. Setup Dataset Generation
    success = run_step("Dataset Generation", ["src/dataset.py"])
    if not success:
        sys.exit(1)

    print("\n" + "=" * 60)
    print("ALL ENVIRONMENT COMPONENT SETUP IS COMPLETE!")
    print("=" * 60)
    print("\nYou are now ready to run:")
    print("1. Fine-tuning: Run 'python src/train.py' to train your model.")
    print("2. Web Studio Dashboard: Run 'python src/server.py' and open http://127.0.0.1:5000 in your browser.")
    print("=" * 60)

if __name__ == "__main__":
    setup()