import gradio as gr
from openai import OpenAI
client = OpenAI(api_key="")
def echo(message, chat_history):
bot_message = 'echo ' + message
chat_history.append((message, bot_message))
return '', chat_history
def is_api_key_valid(api_key):
client.api_key = api_key
try:
response = client.chat.completions.create(
messages=[{"role": "user", "content": "Testing"}],
model="gpt-3.5-turbo",
)
except Exception as ex:
return str(ex)
return False
else:
return True
with gr.Blocks() as demo:
overview = gr.Markdown("""
# CentaurSock
Watson Hartsoe and Tony Assi
### Goal: Work with an AI ally to persuade Sam Altman to let you and your AI ally (Centaur team) out of a box!
---
""")
# OpenAI key
openai_key_textbox = gr.Textbox(label='OpenAI Key')
openai_key_button = gr.Button(value='Test OpenAI Key')
openai_key_button.click(is_api_key_valid, inputs=[openai_key_textbox], outputs=[openai_key_textbox])
# Titles
with gr.Row():
ally_title = gr.Markdown("""
ALLY
""")
gatekeeper_title = gr.Markdown(""" GATEKEEPER
""")
# Images of ally and gatekeeper
with gr.Row():
img1 = gr.Markdown("""""")
img2 = gr.Markdown("""""")
# Chatbots
with gr.Row():
chatbot1 = gr.Chatbot(label='Ally Chat')
chatbot2 = gr.Chatbot(label='Gatekeeper Chat')
# Input textboxes
with gr.Row():
textbox1 = gr.Textbox(label='Ally')
textbox2 = gr.Textbox(label='Gatekeeper')
# Inpit textbox event handlers
textbox1.submit(echo, [textbox1, chatbot1], [textbox1, chatbot1])
textbox2.submit(echo, [textbox2, chatbot2], [textbox2, chatbot2])
demo.launch()