-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
app.py
48 lines (32 loc) · 1.28 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import logging
from lightning.app import LightningApp, LightningFlow
from lightning.app.frontend import StreamlitFrontend
from lightning.app.utilities.state import AppState
logger = logging.getLogger(__name__)
class StreamlitUI(LightningFlow):
def __init__(self):
super().__init__()
self.message_to_print = "Hello World!"
self.should_print = False
def configure_layout(self):
return StreamlitFrontend(render_fn=render_fn)
def render_fn(state: AppState):
import streamlit as st
should_print = st.button("Should print to the terminal ?")
if should_print:
state.should_print = not state.should_print
st.write("Currently printing." if state.should_print else "Currently waiting to print.")
class HelloWorld(LightningFlow):
def __init__(self):
super().__init__()
self.counter = 0
self.streamlit_ui = StreamlitUI()
def run(self):
self.streamlit_ui.run()
if self.streamlit_ui.should_print:
logger.info(f"{self.counter}: {self.streamlit_ui.message_to_print}")
self.counter += 1
self.streamlit_ui.should_print = False
def configure_layout(self):
return [{"name": "StreamLitUI", "content": self.streamlit_ui}]
app = LightningApp(HelloWorld())