import streamlit as st import pexpect import time import streamlit.components.v1 as components 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") st.write("For a fully playable version of this game with images, go here : https://github.com/Taiko3615/Danse-Macabre") # creating a single-element container placeholder = st.empty() if "text" not in st.session_state: st.session_state["text"] = "" def submit(): st.session_state["saved_text"] = st.session_state["text"] child.sendline(st.session_state["saved_text"]) st.session_state["text"] = "" user_input = st.text_input("What do you do or say ?",key = "text", on_change=submit) while True: st.session_state.m = "" 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.session_state.m += msg components.html( f"""

{st.session_state.m}

""", height= 610 ) #Try again in X sec time.sleep(0.5)