Hugorowan commited on
Commit
74c2d80
1 Parent(s): 244e5a2

Create Main

Browse files
Files changed (1) hide show
  1. Main +40 -0
Main ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def talk_to_chatgpt(message):
4
+ """Talks to a ChatGPT and returns its response."""
5
+ url = "https://chat.openai.com/v1/engines/chat/generate"
6
+ headers = {
7
+ "Authorization": "Bearer YOUR_API_KEY",
8
+ "Content-Type": "application/json",
9
+ }
10
+ data = {
11
+ "prompt": message,
12
+ "temperature": 0.7,
13
+ "max_tokens": 100,
14
+ }
15
+ response = requests.post(url, headers=headers, data=data)
16
+ response.raise_for_status()
17
+ return response.json()["choices"][0]["text"]
18
+
19
+ def main():
20
+ """Starts a conversation between you and two ChatGPTs."""
21
+ chatgpt1 = gr.inputs.Textbox(label="ChatGPT 1")
22
+ chatgpt2 = gr.inputs.Textbox(label="ChatGPT 2")
23
+
24
+ chatgpt1_response = gr.outputs.Textbox(label="ChatGPT 1 Response")
25
+ chatgpt2_response = gr.outputs.Textbox(label="ChatGPT 2 Response")
26
+
27
+ @gr.interaction(
28
+ title="Talk to ChatGPTs",
29
+ description="Start a conversation with two ChatGPTs",
30
+ inputs=[chatgpt1, chatgpt2],
31
+ outputs=[chatgpt1_response, chatgpt2_response],
32
+ )
33
+ def talk_to_chatgpts(chatgpt1_message, chatgpt2_message):
34
+ chatgpt1_response = talk_to_chatgpt(chatgpt1_message)
35
+ chatgpt2_response = talk_to_chatgpt(chatgpt2_message)
36
+
37
+ return chatgpt1_response, chatgpt2_response
38
+
39
+ if __name__ == "__main__":
40
+ main()