File size: 1,573 Bytes
1f4e4ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, redirect, url_for
import subprocess
import threading
import time
import os

app = Flask(__name__)

# Global variable to track Streamlit process
streamlit_process = None

def start_streamlit():
    """Start Streamlit app in background"""
    global streamlit_process
    try:
        streamlit_process = subprocess.Popen([
            'streamlit', 'run', 'app_enhanced.py', 
            '--server.port=8502',
            '--server.headless=true'
        ])
        print("Streamlit app started on port 8502")
    except Exception as e:
        print(f"Error starting Streamlit: {e}")

@app.route('/')
def landing_page():
    """Serve the landing page"""
    return render_template('index.html')

@app.route('/app')
def launch_app():
    """Redirect to Streamlit app"""
    return redirect('http://localhost:8502')

@app.route('/start-streamlit')
def start_streamlit_endpoint():
    """Start Streamlit if not running"""
    global streamlit_process
    if streamlit_process is None or streamlit_process.poll() is not None:
        threading.Thread(target=start_streamlit, daemon=True).start()
        time.sleep(3)  # Give Streamlit time to start
    return redirect('http://localhost:8502')

if __name__ == '__main__':
    # Start Streamlit in background
    threading.Thread(target=start_streamlit, daemon=True).start()
    
    # Start Flask server
    print("Starting Flask server on http://localhost:5000")
    print("Streamlit app will be available on http://localhost:8502")
    app.run(host='0.0.0.0', port=5000, debug=True)