From 0856fd87284b0e36944645c0cd0b9e686cbac3ce Mon Sep 17 00:00:00 2001 From: Stan Soldatov <118521851+iwatkot@users.noreply.github.com> Date: Tue, 24 Dec 2024 19:57:17 +0100 Subject: [PATCH] WebUI updates --- webui/config.py | 11 +++++++++++ webui/generator.py | 14 +++++++++----- webui/tools/background.py | 9 +++------ webui/tools/dem.py | 9 +++------ 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/webui/config.py b/webui/config.py index 8d3c9d6..2f520f3 100644 --- a/webui/config.py +++ b/webui/config.py @@ -20,6 +20,8 @@ STREAMLIT_COMMUNITY_KEY = "HOSTNAME" STREAMLIT_COMMUNITY_VALUE = "streamlit" +PUBLIC_HOSTNAME_KEY = "PUBLIC_HOSTNAME" +PUBLIC_HOSTNAME_VALUE = "maps4fs" DOCS_DIRECTORY = os.path.join(WORKING_DIRECTORY, "docs") MD_FILES = { @@ -58,6 +60,15 @@ def is_on_community_server() -> bool: return os.environ.get(STREAMLIT_COMMUNITY_KEY) == STREAMLIT_COMMUNITY_VALUE +def is_public() -> bool: + """Check if the script is running on a public server. + + Returns: + bool: True if the script is running on a public server, False otherwise. + """ + return os.environ.get(PUBLIC_HOSTNAME_KEY) == PUBLIC_HOSTNAME_VALUE + + def remove_with_delay_without_blocking( file_path: str, logger: mfs.Logger, diff --git a/webui/generator.py b/webui/generator.py index aae4a71..2896cf6 100644 --- a/webui/generator.py +++ b/webui/generator.py @@ -48,7 +48,9 @@ def __init__(self): self.logger = mfs.Logger(level="INFO", to_file=False) self.community = config.is_on_community_server() + self.public = config.is_public() self.logger.debug("The application launched on the community server: %s", self.community) + self.logger.debug("The application launched on a public server: %s", self.public) self.left_column, self.right_column = st.columns(2, gap="large") @@ -117,7 +119,8 @@ def add_left_widgets(self) -> None: st.title(Messages.TITLE) - if not self.community: + # Only for a local Docker version. + if not self.community and not self.public: versions = config.get_versions(self.logger) try: if versions: @@ -141,7 +144,6 @@ def add_left_widgets(self) -> None: st.write(Messages.MAIN_PAGE_DESCRIPTION) if self.community: st.info(Messages.MAIN_PAGE_COMMUNITY_WARNING) - # st.info(Messages.TERRAIN_RELOAD) st.markdown("---") # Game selection (FS22 or FS25). @@ -169,6 +171,8 @@ def add_left_widgets(self) -> None: size_options = ["2048x2048", "4096x4096", "8192x8192", "16384x16384", "Custom"] if self.community: size_options = size_options[:1] + if self.public: + size_options = size_options[:2] # Map size selection. st.write("Select size of the map:") @@ -196,7 +200,7 @@ def add_left_widgets(self) -> None: self.map_size_input = f"{custom_map_size_input}x{custom_map_size_input}" - if self.community: + if self.community or self.public: st.warning( "💡 If you run the tool locally, you can generate larger maps, even with the custom size. \n" ) @@ -486,7 +490,7 @@ def generate_map(self) -> None: water_depth=self.water_depth, ) - if self.community: + if self.community or self.public: add_to_queue(session_name) for position in wait_in_queue(session_name): self.status_container.info( @@ -527,7 +531,7 @@ def generate_map(self) -> None: f"An error occurred while generating the map: {repr(e)}.", icon="❌" ) finally: - if self.community: + if self.community or self.public: remove_from_queue(session_name) def show_preview(self, mp: mfs.Map) -> None: diff --git a/webui/tools/background.py b/webui/tools/background.py index 6908fae..61ce1dc 100644 --- a/webui/tools/background.py +++ b/webui/tools/background.py @@ -3,7 +3,7 @@ import cv2 import numpy as np import streamlit as st -from config import INPUT_DIRECTORY, is_on_community_server +from config import INPUT_DIRECTORY, is_on_community_server, is_public from tools.tool import Tool from maps4fs.toolbox.background import plane_from_np @@ -23,11 +23,8 @@ class ConvertImageToObj(Tool): download_path = None def content(self): - if is_on_community_server(): - st.warning( - "💡 This tool is disabled on StreamLit community hosting. \n" - "If you want to use it, consider running the application locally." - ) + if is_on_community_server() or is_public(): + st.warning("💡 This tool is available in the local version of the tool.") return if "convertedtoobj" not in st.session_state: st.session_state.convertedtoobj = False diff --git a/webui/tools/dem.py b/webui/tools/dem.py index 3377e00..d26b29a 100644 --- a/webui/tools/dem.py +++ b/webui/tools/dem.py @@ -2,7 +2,7 @@ import streamlit as st import streamlit.components.v1 as components -from config import INPUT_DIRECTORY, is_on_community_server +from config import INPUT_DIRECTORY, is_on_community_server, is_public from osmp import get_bbox, get_center, get_preview from tools.tool import Tool @@ -22,11 +22,8 @@ class GeoTIFFWindowingTool(Tool): download_path = None def content(self): - if is_on_community_server(): - st.warning( - "💡 This tool is disabled on StreamLit community hosting. \n" - "If you want to use it, consider running the application locally." - ) + if is_on_community_server() or is_public(): + st.warning("💡 This tool is available in the local version of the tool.") return if "windowed" not in st.session_state: st.session_state.windowed = False