RickyRubini commited on
Commit
35c71f8
·
1 Parent(s): 0d33247

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +48 -0
  2. requirements.txt +2 -0
main.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ openai.api_key = "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"
5
+
6
+ start_sequence = "\nAI:"
7
+ restart_sequence = "\nHuman: "
8
+
9
+ 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: "
10
+
11
+ def openai_create(prompt):
12
+
13
+ response = openai.Completion.create(
14
+ model="text-davinci-003",
15
+ prompt=prompt,
16
+ temperature=0,
17
+ max_tokens=256,
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
+ def chatgpt_clone(input, history):
28
+ history = history or []
29
+ s = list(sum(history, ()))
30
+ s.append(input)
31
+ inp = ' '.join(s)
32
+ output = openai_create(inp)
33
+ history.append((input, output))
34
+ return history, history
35
+
36
+ block = gr.Blocks()
37
+
38
+
39
+ with block:
40
+ gr.Markdown("""<h1><center>Build Yo'own ChatGPT with OpenAI API & Gradio</center></h1>
41
+ """)
42
+ chatbot = gr.Chatbot()
43
+ message = gr.Textbox(placeholder=prompt)
44
+ state = gr.State()
45
+ submit = gr.Button("SEND")
46
+ submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
47
+
48
+ block.launch(debug = True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ gradio