Skip to content

Commit

Permalink
WebUI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot authored Dec 24, 2024
1 parent 29f2c75 commit 0856fd8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
11 changes: 11 additions & 0 deletions webui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions webui/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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:
Expand All @@ -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).
Expand Down Expand Up @@ -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:")
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions webui/tools/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions webui/tools/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 0856fd8

Please sign in to comment.