Spaces:
Sleeping
Sleeping
trying something
Browse files
app.py
CHANGED
@@ -1,9 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
import io, sys, time
|
3 |
from utils import *
|
|
|
4 |
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import io, sys, time
|
3 |
from utils import *
|
4 |
+
from client import CobotController
|
5 |
|
6 |
+
import uuid
|
7 |
|
8 |
+
@st.cache_resource
|
9 |
+
def create_cobot_client():
|
10 |
+
user_id = get_user_id()
|
11 |
+
user, passwd, host, endpoint, port = get_credentials()
|
12 |
+
client = CobotController(user, passwd, host, port, endpoint, user_id)
|
13 |
+
|
14 |
+
@st.cache_resource
|
15 |
+
def get_user_id2():
|
16 |
+
return str(uuid.uuid4())
|
17 |
+
|
18 |
+
st.write(get_user_id2())
|
19 |
+
|
20 |
+
# render_log_window()
|
21 |
+
|
22 |
+
# for i in range(10):
|
23 |
+
# print(f"logger: {i}")
|
24 |
+
# time.sleep(1)
|
utils.py
CHANGED
@@ -1,32 +1,47 @@
|
|
1 |
import streamlit as st
|
2 |
-
import uuid, io, sys
|
3 |
|
4 |
def get_user_id():
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
class StdoutRedirector(io.StringIO):
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
def render_log_window():
|
32 |
st.markdown("""
|
|
|
1 |
import streamlit as st
|
2 |
+
import uuid, io, sys, os
|
3 |
|
4 |
def get_user_id():
|
5 |
+
if "user_id" not in st.session_state:
|
6 |
+
query_params = st.query_params
|
7 |
+
user_id = query_params.get("user_id", None)
|
8 |
+
if not user_id:
|
9 |
+
user_id = str(uuid.uuid4())
|
10 |
+
st.query_params["user_id"] = user_id
|
11 |
+
st.session_state.user_id = user_id
|
12 |
+
return st.session_state.user_id
|
13 |
+
|
14 |
+
def get_credentials(use_own_creds: bool):
|
15 |
+
if use_own_creds:
|
16 |
+
HIVEMQ_USERNAME = st.text_input("HIVEMQ Username", type="password")
|
17 |
+
HIVEMQ_PASSWORD = st.text_input("HIVEMQ Password", type="password")
|
18 |
+
HIVEMQ_HOST = st.text_input("HIVEMQ Host", type="password")
|
19 |
+
DEVICE_ENDPOINT = st.text_input("Device ID", type="password")
|
20 |
+
PORT = st.number_input("Port", min_value=1, step=1, value=8883)
|
21 |
+
else:
|
22 |
+
HIVEMQ_USERNAME = os.environ.get("HIVEMQ_USERNAME")
|
23 |
+
HIVEMQ_PASSWORD = os.environ.get("HIVEMQ_PASSWORD")
|
24 |
+
HIVEMQ_HOST = os.environ.get("HIVEMQ_HOST")
|
25 |
+
DEVICE_ENDPOINT = os.environ.get("DEVICE_ID")
|
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 |
st.markdown("""
|