hrishikeshagi commited on
Commit
b226e23
1 Parent(s): 30bc44e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ #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
5
+
6
+ openai.api_key = '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'
7
+
8
+ def openai_chat(prompt):
9
+ completions = openai.Completion.create(
10
+ engine="text-davinci-003",
11
+ prompt=prompt,
12
+ max_tokens=2048,
13
+ n=1,
14
+ temperature=0.5,
15
+ )
16
+
17
+ message = completions.choices[0].text
18
+ return message.strip()
19
+
20
+ def chatbot(input, history=[]):
21
+ output = openai_chat(input)
22
+ history.append((input, output))
23
+ return history, history
24
+
25
+ gr.Interface( title = 'An Alternative to chatGPT - Built by Hrishikesh', fn = chatbot,
26
+ inputs = ["text",'state'],
27
+ outputs = ["chatbot",'state']).launch(debug = True )