Spaces:
Runtime error
Runtime error
File size: 1,427 Bytes
a58f876 193e7df 798fb24 b7524fd 193e7df cb7550a e7dbad9 d171dcd 3c0a606 cb7550a 3c0a606 cb7550a 8c1fd84 b68e9b8 cb7550a dfaa337 cb7550a dfaa337 cb7550a dfaa337 73ac9b4 cb7550a d171dcd cb7550a 8e2e4ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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()
if "text" not in st.session_state:
st.session_state["text"] = ""
if "saved_text" not in st.session_state:
st.session_state["saved_text"] = ""
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)
|