Hugo Garcia-Cotte commited on
Commit
8a7e1d1
1 Parent(s): a7a08cf

Add first version of the game file

Browse files
Files changed (1) hide show
  1. app.py +22 -49
app.py CHANGED
@@ -1,57 +1,30 @@
1
- import os
2
-
3
- import openai
4
  import streamlit as st
5
- from streamlit_chat import message
6
-
7
- st.set_page_config(
8
- page_title="ChatGPT",
9
- page_icon=":robot:"
10
- )
11
-
12
- st.header("ChatGPT")
13
-
14
- if 'generated' not in st.session_state:
15
- st.session_state['generated'] = []
16
- if 'past' not in st.session_state:
17
- st.session_state['past'] = []
18
- if 'messages' not in st.session_state:
19
- st.session_state['messages'] = [
20
- {"role": "system", "content": "You are a helpful assistant that translates English to Chinese."}]
21
-
22
 
23
- def query(question):
24
- st.session_state['messages'].append({"role": "user", "content": question})
25
 
26
- openai.api_key = os.environ['OPENAI_API_KEY']
27
- response = openai.ChatCompletion.create(
28
- model="gpt-3.5-turbo",
29
- temperature=1.2,
30
- messages=st.session_state['messages'],
31
- max_tokens=2000
32
- )
33
 
34
- answer = response['choices'][0]['message']['content']
35
- st.session_state['messages'].append({"role": "assistant", "content": answer})
36
- return answer
37
 
38
-
39
- with st.form("my_form"):
40
- # Create a text input for the first field
41
- input_text = st.text_input("You: ", "Hello, how are you?", key="input")
42
-
43
- # Every form must have a submit button.
44
- # c1, c2 = st.columns([2, 2])
45
- submitted = st.form_submit_button("🤖 Submit")
46
-
47
- if submitted and input_text:
48
- output = query(input_text, )
49
  if output:
50
- st.session_state.past.append(input_text)
51
- st.session_state.generated.append(output)
 
 
 
 
52
 
53
- if st.session_state['generated']:
 
54
 
55
- for i in range(len(st.session_state['generated']) - 1, -1, -1):
56
- message(st.session_state["generated"][i], key=str(i))
57
- message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
 
 
 
 
 
1
  import streamlit as st
2
+ import subprocess
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ st.title("Command-line interface")
 
5
 
6
+ # Define the command to be executed
7
+ cmd = ["python", "danse_macabre.py"]
 
 
 
 
 
8
 
9
+ # Create a subprocess object
10
+ process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
 
11
 
12
+ # Loop until the Python program exits
13
+ while process.poll() is None:
14
+ # Check if the program has output
15
+ output = process.stdout.readline()
 
 
 
 
 
 
 
16
  if output:
17
+ st.text(output.strip())
18
+
19
+ # Check if the program has an error
20
+ error = process.stderr.readline()
21
+ if error:
22
+ st.error(error.strip())
23
 
24
+ # Get user input using a Streamlit text_input component
25
+ user_input = st.text_input("Input", "")
26
 
27
+ # Pass user input to the Python program
28
+ if user_input:
29
+ process.stdin.write(user_input + "\n")
30
+ process.stdin.flush()