Spaces:
Paused
Paused
File size: 3,263 Bytes
a7c22d2 |
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 101 102 103 104 105 106 107 108 109 110 111 112 113 |
#!/usr/bin/env python3
"""
Startup script for FinSolve RAG System
Runs both FastAPI and Streamlit simultaneously
"""
import subprocess
import sys
import time
import os
import signal
import threading
from pathlib import Path
def run_fastapi():
"""Run FastAPI server"""
print("π Starting FastAPI server on http://localhost:8000")
try:
# Run FastAPI with uvicorn
subprocess.run([
sys.executable, "-m", "uvicorn",
"api:app",
"--host", "0.0.0.0",
"--port", "8000",
"--reload"
], check=True)
except KeyboardInterrupt:
print("π FastAPI server stopped")
except Exception as e:
print(f"β Error running FastAPI: {e}")
def run_streamlit():
"""Run Streamlit app"""
print("π Starting Streamlit app on http://localhost:8501")
try:
# Wait a moment for FastAPI to start
time.sleep(3)
# Run Streamlit
subprocess.run([
sys.executable, "-m", "streamlit", "run",
"streamlit_app.py",
"--server.port", "8501",
"--server.address", "0.0.0.0"
], check=True)
except KeyboardInterrupt:
print("π Streamlit app stopped")
except Exception as e:
print(f"β Error running Streamlit: {e}")
def check_dependencies():
"""Check if all required dependencies are installed"""
required_packages = [
'fastapi', 'uvicorn', 'streamlit', 'chromadb',
'sentence-transformers', 'openai', 'pandas', 'plotly'
]
missing_packages = []
for package in required_packages:
try:
__import__(package.replace('-', '_'))
except ImportError:
missing_packages.append(package)
if missing_packages:
print(f"β Missing packages: {', '.join(missing_packages)}")
print("π¦ Install with: pip install -r requirements.txt")
return False
print("β
All dependencies satisfied")
return True
def signal_handler(signum, frame):
"""Handle shutdown signals"""
print("\nπ Shutting down servers...")
sys.exit(0)
def main():
"""Main function to start both servers"""
print("π€ FinSolve RAG System Startup")
print("="*50)
# Check dependencies
if not check_dependencies():
sys.exit(1)
# Set up signal handlers for graceful shutdown
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
print("\nποΈ Starting Complete Tech Stack:")
print("π‘ FastAPI: http://localhost:8000")
print("π Streamlit: http://localhost:8501")
print("π API Docs: http://localhost:8000/docs")
print("\nπ‘ Press Ctrl+C to stop both servers\n")
try:
# Start FastAPI in a separate thread
fastapi_thread = threading.Thread(target=run_fastapi, daemon=True)
fastapi_thread.start()
# Run Streamlit in main thread
run_streamlit()
except KeyboardInterrupt:
print("\nπ Received shutdown signal")
except Exception as e:
print(f"β Startup error: {e}")
finally:
print("π Goodbye!")
if __name__ == "__main__":
main() |