forked from Top34051/chat-with-gpt-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopinion-climate.py
73 lines (52 loc) · 1.54 KB
/
opinion-climate.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
72
73
import streamlit as st
from utils.session import session_setup, modify_prompt, modify_chat_history
from utils.components import show_response_count, finish_button, show_finish_status
from utils.chatbot import get_response
from utils.database import submit_to_database
st.set_page_config(
layout='wide',
page_title='GPT-3 chatbot',
page_icon='🤖'
)
def main():
# Set up session
session_setup()
# Show information
st.title('GPT-3 chatbot')
st.info(
'Your goal is to **exchange your opinion** with GPT-3 on **climate change**.'
)
# Show chat history
st.text_area(
'Chat history',
value=st.session_state['chat_history'],
height=500
)
# Get the user input
user_input = st.text_input(
'You:',
value='',
key=str(st.session_state['response_count'])
)
# Get the response from gpt-3 (None if not possible)
response = get_response(user_input)
# Save response
if response != None:
# Modify prompt
modify_prompt(user_input, response)
# Modify chat history
modify_chat_history(user_input, response)
# Increment response count
st.session_state['response_count'] += 1
# Rerun page
st.experimental_rerun()
# Show response count
show_response_count()
# Update session status
finish_button()
# Show finish status
show_finish_status()
# Submit survey to database if finished
submit_to_database('opinion-climate')
if __name__ == '__main__':
main()