import os import uvicorn from fastapi import FastAPI from starlette.middleware.wsgi import WSGIMiddleware from starlette.responses import RedirectResponse # Use this library to make Streamlit WSGI-compatible from streamlit_wsgi import StreamlitPatcher # Import your FastAPI app from api.main import api_app # Create and patch the Streamlit app sp = StreamlitPatcher() streamlit_script_path = os.path.join("streamlit_app", "app.py") streamlit_app = sp.create_app(streamlit_script_path) sp.patch() # Apply patches for Streamlit to work correctly # The main FastAPI app that will serve everything app = FastAPI() # Mount the API and the Streamlit UI app.mount('/api', api_app) app.mount('/ui', WSGIMiddleware(streamlit_app)) @app.get("/") def root(): # Redirect root to the Streamlit UI return RedirectResponse(url="/ui")