gursi26 commited on
Commit
ef09ab9
1 Parent(s): 2554ae8

trying something

Browse files
Files changed (2) hide show
  1. app.py +19 -4
  2. utils.py +38 -23
app.py CHANGED
@@ -1,9 +1,24 @@
1
  import streamlit as st
2
  import io, sys, time
3
  from utils import *
 
4
 
5
- render_log_window()
6
 
7
- for i in range(10):
8
- print(f"logger: {i}")
9
- time.sleep(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- 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
  class StdoutRedirector(io.StringIO):
15
- def __init__(self, log_area, max_lines=20):
16
- super().__init__()
17
- self.log_area = log_area
18
- self.logs = []
19
- self.max_lines = max_lines
20
 
21
- def write(self, message):
22
- if message.strip():
23
- self.logs.append(message.strip())
24
- if len(self.logs) > self.max_lines:
25
- self.logs.pop(0)
26
- self.log_area.markdown(
27
- f"<div class='log-window'>{'<br>'.join(self.logs)}</div>",
28
- unsafe_allow_html=True
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("""