From 18b4152f394c36892aaf096b9c50dbf4c650b30e Mon Sep 17 00:00:00 2001 From: puke Date: Tue, 28 Oct 2025 11:31:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=A5=E5=8F=A3=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/__init__.py | 10 ---------- api/app.py | 35 ++++++++++++++++++++++++++++++--- restart_web.sh | 2 +- start_api.py | 46 -------------------------------------------- start_web.sh | 2 +- web.py => web/app.py | 1 + 6 files changed, 35 insertions(+), 61 deletions(-) delete mode 100755 start_api.py rename web.py => web/app.py (99%) diff --git a/api/__init__.py b/api/__init__.py index 2404133..606ac21 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -3,13 +3,3 @@ ReelForge API Layer FastAPI-based REST API for video generation services. """ - -# Lazy import to avoid loading dependencies until needed -def get_app(): - """Get FastAPI app instance (lazy loading)""" - from api.app import app - return app - - -__all__ = ["get_app"] - diff --git a/api/app.py b/api/app.py index 2c53013..950ce86 100644 --- a/api/app.py +++ b/api/app.py @@ -2,8 +2,15 @@ ReelForge FastAPI Application Main FastAPI app with all routers and middleware. + +Run this script to start the FastAPI server: + uv run python api/app.py + +Or with custom settings: + uv run python api/app.py --host 0.0.0.0 --port 8080 --reload """ +import argparse from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware @@ -124,10 +131,32 @@ async def root(): if __name__ == "__main__": import uvicorn + # Parse command line arguments + parser = argparse.ArgumentParser(description="Start ReelForge API Server") + parser.add_argument("--host", default="0.0.0.0", help="Host to bind to") + parser.add_argument("--port", type=int, default=8000, help="Port to bind to") + parser.add_argument("--reload", action="store_true", help="Enable auto-reload") + + args = parser.parse_args() + + # Print startup banner + print(f""" +╔══════════════════════════════════════════════════════════════╗ +║ ReelForge API Server ║ +╚══════════════════════════════════════════════════════════════╝ + +Starting server at http://{args.host}:{args.port} +API Docs: http://{args.host}:{args.port}/docs +ReDoc: http://{args.host}:{args.port}/redoc + +Press Ctrl+C to stop the server +""") + + # Start server uvicorn.run( "api.app:app", - host=api_config.host, - port=api_config.port, - reload=api_config.reload, + host=args.host, + port=args.port, + reload=args.reload, ) diff --git a/restart_web.sh b/restart_web.sh index ceb615e..5935b22 100755 --- a/restart_web.sh +++ b/restart_web.sh @@ -29,7 +29,7 @@ fi # Start Streamlit in background with nohup echo "🚀 Starting ReelForge Web UI in background..." -nohup uv run streamlit run web.py --server.port $PORT > nohup.out 2>&1 & +nohup uv run streamlit run web/app.py --server.port $PORT > nohup.out 2>&1 & # Wait a moment and check if the process started sleep 2 diff --git a/start_api.py b/start_api.py deleted file mode 100755 index 26c1b7b..0000000 --- a/start_api.py +++ /dev/null @@ -1,46 +0,0 @@ -""" -Start ReelForge API Server - -Run this script to start the FastAPI server: - uv run python start_api.py - -Or with custom settings: - uv run python start_api.py --host 0.0.0.0 --port 8080 --reload -""" - -import argparse -import uvicorn - - -def main(): - """Start API server""" - parser = argparse.ArgumentParser(description="Start ReelForge API Server") - parser.add_argument("--host", default="0.0.0.0", help="Host to bind to") - parser.add_argument("--port", type=int, default=8000, help="Port to bind to") - parser.add_argument("--reload", action="store_true", help="Enable auto-reload") - - args = parser.parse_args() - - print(f""" -╔══════════════════════════════════════════════════════════════╗ -║ ReelForge API Server ║ -╚══════════════════════════════════════════════════════════════╝ - -Starting server at http://{args.host}:{args.port} -API Docs: http://{args.host}:{args.port}/docs -ReDoc: http://{args.host}:{args.port}/redoc - -Press Ctrl+C to stop the server -""") - - uvicorn.run( - "api.app:app", - host=args.host, - port=args.port, - reload=args.reload, - ) - - -if __name__ == "__main__": - main() - diff --git a/start_web.sh b/start_web.sh index f483a5e..4a4dc1c 100755 --- a/start_web.sh +++ b/start_web.sh @@ -15,5 +15,5 @@ if [ ! -f config.yaml ]; then fi # Start Streamlit -uv run streamlit run web.py +uv run streamlit run web/app.py diff --git a/web.py b/web/app.py similarity index 99% rename from web.py rename to web/app.py index 3b2d26d..4c41694 100644 --- a/web.py +++ b/web/app.py @@ -722,3 +722,4 @@ def main(): if __name__ == "__main__": main() +