Hugo Garcia-Cotte
Finally something working
cb7550a
raw
history blame
1.03 kB
import streamlit as st
import pexpect
import time
if 'child' not in st.session_state:
st.session_state['child'] = pexpect.spawn("python danse_macabre.py", encoding='utf-8', timeout=None)
child = st.session_state['child']
if 'messages' not in st.session_state:
st.session_state['messages'] = []
# creating a single-element container
placeholder = st.empty()
user_input = st.text_input("What do you do or say ?")
if user_input :
child.sendline(str(user_input))
user_input=""
while True:
with placeholder.container():
#Let's see if there's a new message
try :
#If there's no exception it means yes
line = child.read_nonblocking(size=1000, timeout=0)
#Let's add it to the list of messages
st.session_state['messages'].append(line)
except:
pass
# Display the list of messages in the placeholder
for msg in st.session_state['messages']:
st.write(msg)
#Try again in X sec
time.sleep(0.5)