File size: 1,258 Bytes
74c2d80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()