-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChatGPT_Web_Application.py
71 lines (56 loc) · 2.07 KB
/
ChatGPT_Web_Application.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# import streamlit as st
# st.title("ChatGPT-like Web App")
# #storing the chat
# if 'generated' not in st.session_state:
# st.session_state['generated'] = []
# if 'past' not in st.session_state:
# st.session_state['past'] = []
# user_input=st.text_input("You:",key='input')
# if user_input:
# output=generate_response(user_input)
# #store the output
# st.session_state['past'].append(user_input)
# st.session_state['generated'].append(output)
# if st.session_state['generated']:
# for i in range(len(st.session_state['generated'])-1, -1, -1):
# message(st.session_state["generated"][i], key=str(i))
# message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
import streamlit as st
# this loop will let us ask questions continuously
while True:
# Set up the model and prompt
model_engine = "text-davinci-003"
prompt = input('Enter new prompt: ')
if 'exit' in prompt or 'quit' in prompt:
break
# Generate a response
# given the most recent context (4096 characters)
# continue the text up to 2048 tokens ~ 8192 charaters
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
# extracting useful part of response
response = completion.choices[0].text
# printing response
print(response)
st.title("ChatGPT-like Web App")
#storing the chat
if 'generated' not in st.session_state:
st.session_state['generated'] = []
if 'past' not in st.session_state:
st.session_state['past'] = []
user_input=st.text_input("You:",key='input')
if user_input:
output=generate_response(user_input)
#store the output
st.session_state['past'].append(user_input)
st.session_state['generated'].append(output)
if st.session_state['generated']:
for i in range(len(st.session_state['generated'])-1, -1, -1):
message(st.session_state["generated"][i], key=str(i))
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')