-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
38 lines (35 loc) · 1.21 KB
/
Copy pathrun.py
File metadata and controls
38 lines (35 loc) · 1.21 KB
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
import os
import sys
import subprocess
def check_and_install_dependencies():
print("Checking dependencies...")
try:
import fastapi
import uvicorn
import langchain
import chromadb
import pydantic
import pandas
import pypdf
print("All dependencies are already installed.")
except ImportError as e:
print(f"Missing dependency detected: {e.name}. Installing from requirements.txt...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("Dependencies installed successfully.")
except Exception as err:
print(f"Failed to install dependencies: {err}")
sys.exit(1)
def run_server():
print("Starting FastAPI Backend Server on port 8000...")
try:
import uvicorn
uvicorn.run("backend.main:app", host="0.0.0.0", port=8000, reload=True)
except KeyboardInterrupt:
print("\nServer stopped by user.")
except Exception as e:
print(f"Error starting server: {e}")
if __name__ == "__main__":
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
check_and_install_dependencies()
run_server()