2GPT / Main
Hugorowan's picture
Create Main
74c2d80
import gradio as gr
def talk_to_chatgpt(message):
"""Talks to a ChatGPT and returns its response."""
url = "https://chat.openai.com/v1/engines/chat/generate"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
}
data = {
"prompt": message,
"temperature": 0.7,
"max_tokens": 100,
}
response = requests.post(url, headers=headers, data=data)
response.raise_for_status()
return response.json()["choices"][0]["text"]
def main():
"""Starts a conversation between you and two ChatGPTs."""
chatgpt1 = gr.inputs.Textbox(label="ChatGPT 1")
chatgpt2 = gr.inputs.Textbox(label="ChatGPT 2")
chatgpt1_response = gr.outputs.Textbox(label="ChatGPT 1 Response")
chatgpt2_response = gr.outputs.Textbox(label="ChatGPT 2 Response")
@gr.interaction(
title="Talk to ChatGPTs",
description="Start a conversation with two ChatGPTs",
inputs=[chatgpt1, chatgpt2],
outputs=[chatgpt1_response, chatgpt2_response],
)
def talk_to_chatgpts(chatgpt1_message, chatgpt2_message):
chatgpt1_response = talk_to_chatgpt(chatgpt1_message)
chatgpt2_response = talk_to_chatgpt(chatgpt2_message)
return chatgpt1_response, chatgpt2_response
if __name__ == "__main__":
main()