Carlosjr5 commited on
Commit
1ee2227
1 Parent(s): 3ecf2f9

Add application file

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ #pip3 install openai
3
+ import openai
4
+ #pip3 install gradio
5
+ import gradio as gr
6
+
7
+ from data import OPENAI_API_KEY
8
+ #if you have OpenAI API key as an environment variable, enable the below
9
+ #openai.api_key = os.getenv("OPENAI_API_KEY")
10
+
11
+ #if you have OpenAI API key as a string, enable the below
12
+ OPEN_AI_KEY = OPENAI_API_KEY
13
+
14
+ openai.api_key = OPEN_AI_KEY
15
+
16
+ start_sequence = "\nAI:"
17
+ restart_sequence = "\nHuman: "
18
+
19
+ prompt = "Feel free to ask any question to this bot, it can find you many solutions.\n\n Tell me a story about human beings... "
20
+
21
+ def openai_create(prompt):
22
+
23
+ response = openai.Completion.create(
24
+ model="text-davinci-003",
25
+ prompt=prompt,
26
+ temperature=0.9,
27
+ max_tokens=150,
28
+ top_p=0,
29
+ frequency_penalty=0,
30
+ presence_penalty=0.6,
31
+ stop=[" Human:", " AI:"]
32
+ )
33
+
34
+ return response.choices[0].text
35
+
36
+
37
+
38
+ def cjrSmartBot(input, history):
39
+ history = history or []
40
+ s = list(sum(history, ()))
41
+ s.append(input)
42
+ inp = ' '.join(s)
43
+ output = openai_create(inp)
44
+ history.append((input, output))
45
+ return history, history
46
+
47
+
48
+ block = gr.Blocks()
49
+
50
+
51
+ with block:
52
+ gr.Markdown("""<h1><center>CarlosJR Smart Bot</center></h1>
53
+ """)
54
+ chatbot = gr.Chatbot()
55
+ message = gr.Textbox(placeholder=prompt)
56
+ state = gr.State()
57
+ submit = gr.Button("SEND")
58
+ submit.click(cjrSmartBot, inputs=[message, state], outputs=[chatbot, state])
59
+
60
+ block.launch(share=True)