YourGodAmaterasu commited on
Commit
0c74f59
1 Parent(s): 3467e62

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import gradio as gr
4
+
5
+ openai.api_key = "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"
6
+
7
+ start_sequence = "\nAI:"
8
+ restart_sequence = "\nHuman: "
9
+
10
+ prompt = "The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: "
11
+
12
+ def openai_create(prompt):
13
+ response = openai.Completion.create(
14
+ model="text-davinci-003",
15
+ prompt=prompt,
16
+ temperature=0.9,
17
+ max_tokens=1500,
18
+ top_p=1,
19
+ frequency_penalty=0,
20
+ presence_penalty=0.6,
21
+ stop=[" Human:", " AI:"]
22
+ )
23
+
24
+ return response.choices[0].text
25
+
26
+
27
+
28
+ def chatgpt_clone(input, history):
29
+ history = history or []
30
+ s = list(sum(history, ()))
31
+ s.append(input)
32
+ inp = ' '.join(s)
33
+ output = openai_create(inp)
34
+ history.append((input, output))
35
+ return history, history
36
+
37
+
38
+ block = gr.Blocks()
39
+
40
+
41
+ with block:
42
+ gr.Markdown("""<h1><center>TestBot</center></h1>
43
+ """)
44
+ chatbot = gr.Chatbot()
45
+ message = gr.Textbox(placeholder=prompt)
46
+ state = gr.State()
47
+ submit = gr.Button("SEND")
48
+ submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
49
+
50
+
51
+ block.launch(share=True)