Spaces:
Sleeping
Sleeping
changes
Browse files
app.py
CHANGED
@@ -1,19 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
import io, sys, time
|
3 |
from utils import *
|
4 |
from client import CobotController
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
class StreamlitRedirector:
|
9 |
-
def write(self, message):
|
10 |
-
if message.strip(): # Avoids writing empty lines
|
11 |
-
st.write(message)
|
12 |
-
|
13 |
-
# Set up the redirection
|
14 |
-
sys.stdout = StreamlitRedirector()
|
15 |
-
|
16 |
|
17 |
user_id = get_user_id()
|
18 |
user, passwd, host, endpoint, port = get_credentials(False)
|
19 |
-
client = CobotController(user, passwd, host, port, endpoint, user_id)
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from utils import *
|
3 |
from client import CobotController
|
4 |
|
5 |
+
render_log_window()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
user_id = get_user_id()
|
8 |
user, passwd, host, endpoint, port = get_credentials(False)
|
9 |
+
client = CobotController(user, passwd, host, port, endpoint, user_id)
|
10 |
+
refresh_once()
|
utils.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import uuid, io, sys, os
|
3 |
|
4 |
def get_user_id():
|
@@ -26,40 +27,17 @@ def get_credentials(use_own_creds: bool):
|
|
26 |
PORT = int(os.environ.get("PORT", 8883))
|
27 |
return HIVEMQ_USERNAME, HIVEMQ_PASSWORD, HIVEMQ_HOST, DEVICE_ENDPOINT, PORT
|
28 |
|
29 |
-
class StdoutRedirector(io.StringIO):
|
30 |
-
def __init__(self, log_area, max_lines=20):
|
31 |
-
super().__init__()
|
32 |
-
self.log_area = log_area
|
33 |
-
self.logs = []
|
34 |
-
self.max_lines = max_lines
|
35 |
-
|
36 |
-
def write(self, message):
|
37 |
-
if message.strip():
|
38 |
-
self.logs.append(message.strip())
|
39 |
-
if len(self.logs) > self.max_lines:
|
40 |
-
self.logs.pop(0)
|
41 |
-
self.log_area.markdown(
|
42 |
-
f"<div class='log-window'>{'<br>'.join(self.logs)}</div>",
|
43 |
-
unsafe_allow_html=True
|
44 |
-
)
|
45 |
-
|
46 |
def render_log_window():
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
overflow-y: auto;
|
52 |
-
font-family: monospace;
|
53 |
-
background-color: var(--background-color);
|
54 |
-
color: var(--text-color);
|
55 |
-
padding: 10px;
|
56 |
-
border-radius: 5px;
|
57 |
-
border: 2px solid white;
|
58 |
-
}
|
59 |
-
</style>
|
60 |
-
""", unsafe_allow_html=True)
|
61 |
|
62 |
-
|
63 |
-
stdout_redirector = StdoutRedirector(log_area)
|
64 |
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit_js_eval import streamlit_js_eval
|
3 |
import uuid, io, sys, os
|
4 |
|
5 |
def get_user_id():
|
|
|
27 |
PORT = int(os.environ.get("PORT", 8883))
|
28 |
return HIVEMQ_USERNAME, HIVEMQ_PASSWORD, HIVEMQ_HOST, DEVICE_ENDPOINT, PORT
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def render_log_window():
|
31 |
+
class StreamlitRedirector:
|
32 |
+
def write(self, message):
|
33 |
+
if message.strip():
|
34 |
+
st.write(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
sys.stdout = StreamlitRedirector()
|
|
|
37 |
|
38 |
+
def refresh_once():
|
39 |
+
has_refreshed = st.query_params.get("has_refreshed", None)
|
40 |
+
if not has_refreshed:
|
41 |
+
st.query_params["has_refreshed"] = True
|
42 |
+
sys.stdout = sys.__stdout__
|
43 |
+
streamlit_js_eval(js_expressions="parent.window.location.reload()")
|