Hugo Garcia-Cotte commited on
Commit
cb7550a
1 Parent(s): 8e2e4ad

Finally something working

Browse files
Files changed (1) hide show
  1. app.py +15 -56
app.py CHANGED
@@ -2,76 +2,35 @@ import streamlit as st
2
  import pexpect
3
  import time
4
 
5
- # Initialize a list of messages
6
- # Initialization
7
- if 'messages' not in st.session_state:
8
- st.session_state['messages'] = []
9
-
10
  if 'child' not in st.session_state:
11
  st.session_state['child'] = pexpect.spawn("python danse_macabre.py", encoding='utf-8', timeout=None)
12
 
13
  child = st.session_state['child']
14
 
 
 
 
15
  # creating a single-element container
16
  placeholder = st.empty()
17
 
18
- user_input = st.empty()
19
- user_input = st.text_input("Enter your message here:")
 
 
20
 
21
  while True:
22
  with placeholder.container():
23
- # Display the list of messages
24
- for msg in st.session_state['messages']:
25
- st.write(msg)
26
-
27
- line = None
28
  try :
 
29
  line = child.read_nonblocking(size=1000, timeout=0)
 
 
30
  except:
31
  pass
32
- if line is not None: st.session_state['messages'].append(line)
33
 
34
- if user_input :
35
- child.sendline(str(user_input))
36
- user_input=""
 
37
  time.sleep(0.5)
38
-
39
-
40
-
41
-
42
- #
43
- # last_line = child.readline()
44
- #
45
- # st.session_state['messages'].append(last_line)
46
- #
47
- # # Display the list of messages
48
- # for msg in st.session_state['messages']:
49
- # st.write(msg)
50
- #
51
- # if ">>>>>" in last_line:
52
- # # Create a text input field for users to enter their messages
53
- # user_input = st.text_input("Enter your message here:")
54
- #
55
- # # Add user's message to the list when the submit button is clicked
56
- # if user_input:
57
- # st.session_state['messages'].append(user_input)
58
- # child.sendline(user_input)
59
-
60
- """
61
-
62
- import pexpect
63
- import time
64
-
65
- # Start the other program
66
- child = pexpect.spawn("python DO_NOT_COMMIT.py", encoding='utf-8', timeout=None)
67
-
68
- while True:
69
- time.sleep(1)
70
- line = None
71
- try :
72
- line = child.read_nonblocking(size=1000, timeout=0)
73
- except:
74
- pass
75
- if line is not None: print(repr(line))
76
- #if ">>>>>" in line: child.sendline(input(">>>>>"))
77
- """
 
2
  import pexpect
3
  import time
4
 
 
 
 
 
 
5
  if 'child' not in st.session_state:
6
  st.session_state['child'] = pexpect.spawn("python danse_macabre.py", encoding='utf-8', timeout=None)
7
 
8
  child = st.session_state['child']
9
 
10
+ if 'messages' not in st.session_state:
11
+ st.session_state['messages'] = []
12
+
13
  # creating a single-element container
14
  placeholder = st.empty()
15
 
16
+ user_input = st.text_input("What do you do or say ?")
17
+ if user_input :
18
+ child.sendline(str(user_input))
19
+ user_input=""
20
 
21
  while True:
22
  with placeholder.container():
23
+ #Let's see if there's a new message
 
 
 
 
24
  try :
25
+ #If there's no exception it means yes
26
  line = child.read_nonblocking(size=1000, timeout=0)
27
+ #Let's add it to the list of messages
28
+ st.session_state['messages'].append(line)
29
  except:
30
  pass
 
31
 
32
+ # Display the list of messages in the placeholder
33
+ for msg in st.session_state['messages']:
34
+ st.write(msg)
35
+ #Try again in X sec
36
  time.sleep(0.5)