-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from time import sleep | ||
|
||
import streamlit as st | ||
|
||
from fmtr.tools.logging_tools import logger | ||
|
||
|
||
class Interface: | ||
""" | ||
Base for using streamlit via classes | ||
""" | ||
|
||
PATH = __file__ | ||
LAYOUT = 'centered' | ||
NAME = 'Base Interface' | ||
|
||
def __init__(self, is_root=False): | ||
""" | ||
Set up page layout and call loop method | ||
""" | ||
logger.debug(f'Running interface loop with state: {st.session_state}...') | ||
|
||
if is_root: | ||
self.set_title() | ||
|
||
self.loop() | ||
|
||
def set_title(self): | ||
""" | ||
Set page title and layout when root interface | ||
""" | ||
|
||
st.set_page_config(page_title=self.NAME, layout=self.LAYOUT) | ||
st.title(self.NAME) | ||
|
||
def loop(self): | ||
""" | ||
Dummy process to simulate a task | ||
""" | ||
|
||
if not st.button('Run Test'): | ||
return | ||
msg = 'Running test...' | ||
with st.spinner(msg): | ||
sleep(3) | ||
st.success("Success!") | ||
|
||
@classmethod | ||
def is_streamlit(cls): | ||
""" | ||
Infer whether we are running within StreamLit | ||
""" | ||
return bool(st.context.headers) | ||
|
||
@classmethod | ||
def launch(cls): | ||
""" | ||
Launch StreamLit, if not already running - otherwise instantiate to run loop method | ||
""" | ||
if cls.is_streamlit(): | ||
cls(is_root=True) | ||
else: | ||
from streamlit.web import bootstrap | ||
bootstrap.run(cls.PATH, False, [], {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.9.4 | ||
0.9.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters