File size: 2,885 Bytes
1d10b0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Quick start script to run the RAG application.
"""
import subprocess
import sys
import os


def check_dependencies():
    """Check if required dependencies are installed."""
    try:
        import streamlit
        import fastapi
        import groq
        return True
    except ImportError:
        return False


def install_dependencies():
    """Install dependencies from requirements.txt."""
    print("Installing dependencies...")
    subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
    print("Dependencies installed successfully!")


def check_env_file():
    """Check if .env file exists."""
    if not os.path.exists(".env"):
        print("\n⚠️  Warning: .env file not found!")
        print("Creating .env from .env.example...")
        if os.path.exists(".env.example"):
            with open(".env.example", "r") as src:
                with open(".env", "w") as dst:
                    dst.write(src.read())
            print("βœ… .env file created. Please edit it and add your Groq API key.")
        else:
            print("❌ .env.example not found. Please create .env manually.")
        return False
    return True


def run_streamlit():
    """Run the Streamlit application."""
    print("\nπŸš€ Starting Streamlit application...")
    print("πŸ“± Open your browser to: http://localhost:8501")
    subprocess.run([sys.executable, "-m", "streamlit", "run", "streamlit_app.py"])


def run_api():
    """Run the FastAPI application."""
    print("\nπŸš€ Starting FastAPI server...")
    print("πŸ“± API available at: http://localhost:8000")
    print("πŸ“š API docs at: http://localhost:8000/docs")
    subprocess.run([sys.executable, "api.py"])


def main():
    """Main function."""
    print("=" * 50)
    print("RAG Capstone Project - Quick Start")
    print("=" * 50)
    
    # Check dependencies
    if not check_dependencies():
        print("\nπŸ“¦ Installing dependencies...")
        install_dependencies()
    
    # Check .env file
    env_exists = check_env_file()
    
    if not env_exists:
        print("\n❌ Please configure your .env file before running the application.")
        return
    
    # Ask user what to run
    print("\nWhat would you like to run?")
    print("1. Streamlit Chat Interface (recommended)")
    print("2. FastAPI Backend")
    print("3. Both (requires two terminals)")
    
    choice = input("\nEnter your choice (1-3): ").strip()
    
    if choice == "1":
        run_streamlit()
    elif choice == "2":
        run_api()
    elif choice == "3":
        print("\nπŸ“Œ To run both:")
        print("Terminal 1: python api.py")
        print("Terminal 2: streamlit run streamlit_app.py")
        print("\nStarting Streamlit in this terminal...")
        run_streamlit()
    else:
        print("Invalid choice. Exiting.")


if __name__ == "__main__":
    main()