-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstreamlit_app.py
57 lines (47 loc) · 2.21 KB
/
streamlit_app.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
# filename: debate_app.py
import streamlit as st
import debatemanager
import ststreamer
from contextlib import redirect_stdout
# Function to create and load the debate team
def create_debate_team(api_key):
dm = debatemanager.debate(api_key)
dm.load_team()
return dm
# Function to capture the console output
def capture_console_output(func, *args, **kwargs):
f = ststreamer.ObservableStringIO()
with redirect_stdout(f):
func(*args, **kwargs)
output = f.getvalue()
return output
# Initialize session state
if 'api_key' not in st.session_state:
st.session_state['api_key'] = None
if 'dm' not in st.session_state:
st.session_state['dm'] = None
# App title
st.title("AI Debate Team - Bot v Bot")
# Sidebar for API key input
if st.session_state['api_key'] is None:
with st.sidebar:
api_key = st.text_input("Enter your ChatGPT API key (Tier 1 or higher account):", type="password")
if api_key:
st.session_state['api_key'] = api_key
with st.sidebar:
st.markdown("[feature requests](https://github.com/tevslin/debate_team/discussions)", unsafe_allow_html=True)
st.markdown("[bug reports](https://github.com/tevslin/debate_team/issues)", unsafe_allow_html=True)
st.markdown("[source code](https://github.com/tevslin/debate_team)", unsafe_allow_html=True)
st.markdown("[more info](https://blog.tomevslin.com/2024/02/an-ai-debate.html)", unsafe_allow_html=True)
# If API key is provided, create and load the debate team
if st.session_state['api_key'] and st.session_state['dm'] is None:
with st.spinner("Creating debate team..."):
st.session_state['dm'] = create_debate_team(st.session_state['api_key'])
# Once the debate team is created, ask for a debate proposition
if st.session_state['dm']:
proposition = st.text_input("Enter a debate proposition:")
if proposition:
full_proposition = f"Debate the proposition that {proposition}"
with st.spinner(f"Debating the proposition: {proposition}. Please be patient."):
# Redirect console output and perform the debate
output = capture_console_output(st.session_state['dm'].do_debate, full_proposition)