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'] = [] st.title("Danse Macabre AI Text RPG") st.header("The first Text RPG powered by ChatGPT") st.write("version : alpha 0.0.1") # creating a single-element container placeholder = st.empty() st.session_state["saved_text"] = st.session_state["text"] st.session_state["text"] = "" user_input = st.text_input("What do you do or say ?",key = "text") if user_input : child.sendline(str(st.session_state["saved_text"])) 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)