ahmadiqbal1 commited on
Commit
1de8706
1 Parent(s): f19b8df
Files changed (3) hide show
  1. LICENSE +21 -0
  2. app.py +55 -0
  3. requirements.txt +2 -0
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2022 amrrs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import gradio as gr
4
+
5
+ #if you have OpenAI API key as an environment variable, enable the below
6
+ #openai.api_key = os.getenv("OPENAI_API_KEY")
7
+
8
+ #if you have OpenAI API key as a string, enable the below
9
+ openai.api_key = "xxxxxx"
10
+
11
+ start_sequence = "\nAI:"
12
+ restart_sequence = "\nHuman: "
13
+
14
+ 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: "
15
+
16
+ def openai_create(prompt):
17
+
18
+ response = openai.Completion.create(
19
+ model="text-davinci-003",
20
+ prompt=prompt,
21
+ temperature=0.9,
22
+ max_tokens=150,
23
+ top_p=1,
24
+ frequency_penalty=0,
25
+ presence_penalty=0.6,
26
+ stop=[" Human:", " AI:"]
27
+ )
28
+
29
+ return response.choices[0].text
30
+
31
+
32
+
33
+ def chatgpt_clone(input, history):
34
+ history = history or []
35
+ s = list(sum(history, ()))
36
+ s.append(input)
37
+ inp = ' '.join(s)
38
+ output = openai_create(inp)
39
+ history.append((input, output))
40
+ return history, history
41
+
42
+
43
+ block = gr.Blocks()
44
+
45
+
46
+ with block:
47
+ gr.Markdown("""<h1><center>Build Yo'own ChatGPT with OpenAI API & Gradio</center></h1>
48
+ """)
49
+ chatbot = gr.Chatbot()
50
+ message = gr.Textbox(placeholder=prompt)
51
+ state = gr.State()
52
+ submit = gr.Button("SEND")
53
+ submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
54
+
55
+ block.launch(debug = True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ gradio