File size: 1,789 Bytes
8223b74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
import subprocess

def check_environment():
    """Check if the environment is properly set up"""
    print("Checking environment...")
    
    # Check if .env file exists
    if not os.path.exists(".env"):
        print("Warning: .env file not found. Creating from .env.example...")
        if os.path.exists(".env.example"):
            with open(".env.example", "r") as example_file:
                with open(".env", "w") as env_file:
                    env_file.write(example_file.read())
            print(".env file created successfully.")
        else:
            print("Error: .env.example file not found. Please create a .env file manually.")
            return False
    
    # Check if required packages are installed
    try:
        import fastapi
        import uvicorn
        import langchain
        import transformers
        import torch
        print("All required packages are installed.")
    except ImportError as e:
        print(f"Error: Missing required package: {e}")
        print("Please run: pip install -r requirements.txt")
        return False
    
    return True

def start_application():
    """Start the FastAPI application"""
    if not check_environment():
        print("Environment check failed. Please fix the issues and try again.")
        return
    
    print("\nStarting the application...")
    print("The application will be available at http://localhost:8000")
    print("Press Ctrl+C to stop the application.")
    
    # Start the application using uvicorn
    try:
        subprocess.run([sys.executable, "-m", "uvicorn", "app.main:app", "--reload", "--host", "0.0.0.0", "--port", "8000"])
    except KeyboardInterrupt:
        print("\nApplication stopped.")

if __name__ == "__main__":
    start_application()