Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,16 @@
|
|
1 |
-
import
|
2 |
-
import
|
|
|
|
|
3 |
|
4 |
-
|
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 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
1 |
+
from transformers import DistilBertTokenizer, DistilBertModel
|
2 |
+
import torch
|
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 |
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
inputs = tokenizer(question, text, return_tensors="pt")
|
13 |
+
with torch.no_grad():
|
14 |
+
outputs = model(**inputs)
|
15 |
+
|
16 |
+
print(outputs)
|