Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import gradio
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 = "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"
10
+
11
+ start_sequence = "\nAI:"
12
+ restart_sequence = "\nHuman: "
13
+
14
+ prompt = "Type Your Question Here "
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 = gradio.Blocks()
44
+
45
+
46
+ with block:
47
+ gradio.Markdown("""<h1><center><font color="blue">Electron GPT</font></center></h1>
48
+ """)
49
+ chatbot = gradio.Chatbot()
50
+ message = gradio.Textbox(placeholder=prompt)
51
+ state = gradio.State()
52
+ submit = gradio.Button("SEND")
53
+ submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
54
+
55
+ block.launch(share = True)