Spaces:
Runtime error
Runtime error
Commit
·
edc392d
1
Parent(s):
79f0fe5
Update app.py
Browse files
app.py
CHANGED
@@ -15,30 +15,6 @@ nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
|
|
15 |
# model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")
|
16 |
|
17 |
|
18 |
-
def predict(input, history=[]):
|
19 |
-
# tokenize the new input sentence
|
20 |
-
new_user_input_ids = tokenizer.encode(
|
21 |
-
input + tokenizer.eos_token, return_tensors="pt"
|
22 |
-
)
|
23 |
-
|
24 |
-
# append the new user input tokens to the chat history
|
25 |
-
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
26 |
-
|
27 |
-
# generate a response
|
28 |
-
history = model.generate(
|
29 |
-
bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id
|
30 |
-
).tolist()
|
31 |
-
|
32 |
-
# convert the tokens to text, and then split the responses into lines
|
33 |
-
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
34 |
-
# print('decoded_response-->>'+str(response))
|
35 |
-
response = [
|
36 |
-
(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)
|
37 |
-
] # convert to tuples of list
|
38 |
-
# print('response-->>'+str(response))
|
39 |
-
return response, history
|
40 |
-
|
41 |
-
|
42 |
def func(context, question):
|
43 |
result = nlp(question = question, context=context)
|
44 |
return result['answer']
|
|
|
15 |
# model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def func(context, question):
|
19 |
result = nlp(question = question, context=context)
|
20 |
return result['answer']
|