From ca42998bbfdb77999db8f5c2873cb61654d93df8 Mon Sep 17 00:00:00 2001 From: SMIT PATEL <147633120+smit23patel@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:38:54 +0530 Subject: [PATCH] Update app.py 1. Improved error handling in send_msg to log specific exceptions. 2. Changed logging level to WARNING for better visibility. 3. Removed the list for port and used the port directly from the argument. --- visualizer/app.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/visualizer/app.py b/visualizer/app.py index a91ffd83b..47c3408a8 100644 --- a/visualizer/app.py +++ b/visualizer/app.py @@ -9,14 +9,13 @@ log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) messages = [] -port = [8000] def send_msg(role, text): try: data = {"role": role, "text": text} - response = requests.post(f"http://127.0.0.1:{port[-1]}/send_message", json=data) - except: - logging.info("flask app.py did not start for online log") + response = requests.post(f"http://127.0.0.1:{port}/send_message", json=data) # Updated to use port directly + except Exception as e: # Improved error handling + logging.error(f"Error sending message: {e}") @app.route("/") @@ -63,6 +62,6 @@ def find_avatar_url(role): parser = argparse.ArgumentParser(description='argparse') parser.add_argument('--port', type=int, default=8000, help="port") args = parser.parse_args() - port.append(args.port) - print(f"Please visit http://127.0.0.1:{port[-1]}/ for the front-end display page. \nIn the event of a port conflict, please modify the port argument (e.g., python3 app.py --port 8012).") - app.run(host='0.0.0.0', debug=False, port=port[-1]) + port = args.port # Removed list and used port directly + print(f"Please visit http://127.0.0.1:{port}/ for the front-end display page. \nIn the event of a port conflict, please modify the port argument (e.g., python3 app.py --port 8012).") + app.run(host='0.0.0.0', debug=False, port=port) # Updated to use port directly