Spaces:
Sleeping
Sleeping
| """ | |
| 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() | |