Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,27 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-cased-distilled-squad')
|
4 |
-
model = DistilBertModel.from_pretrained('distilbert-base-cased-distilled-squad')
|
5 |
-
|
6 |
-
question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
|
7 |
|
8 |
-
|
9 |
-
with torch.no_grad():
|
10 |
-
outputs = model(**inputs)
|
11 |
|
12 |
-
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
|
|
16 |
|
17 |
-
def
|
18 |
-
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
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 )
|