Spaces:
Build error
Build error
correct feedback
Browse files
app.py
CHANGED
|
@@ -26,9 +26,8 @@ def chat(message, history=[]):
|
|
| 26 |
last_set_of_ids = history[len(history)-1][2]
|
| 27 |
bot_input_ids = torch.cat([last_set_of_ids, new_user_input_ids], dim=-1)
|
| 28 |
else:
|
| 29 |
-
print("HERE WE GO! ", new_user_input_ids)
|
| 30 |
bot_input_ids = new_user_input_ids
|
| 31 |
-
chat_history_ids = model.generate(bot_input_ids, max_length=
|
| 32 |
response_ids = chat_history_ids[:, bot_input_ids.shape[-1]:][0]
|
| 33 |
response = tokenizer.decode(response_ids, skip_special_tokens=True)
|
| 34 |
history.append((message, response, chat_history_ids))
|
|
@@ -39,13 +38,12 @@ def feedback(text):
|
|
| 39 |
num_return_sequences=1
|
| 40 |
batch = grammar_tokenizer([text],truncation=True,padding='max_length',max_length=64, return_tensors="pt")
|
| 41 |
corrections= grammar_model.generate(**batch,max_length=64,num_beams=2, num_return_sequences=num_return_sequences, temperature=1.5)
|
|
|
|
| 42 |
print("The corrections are: ", corrections)
|
| 43 |
-
if
|
| 44 |
feedback = f'Looks good! Keep up the good work'
|
| 45 |
else:
|
| 46 |
-
|
| 47 |
-
suggestion = [sug for sug in suggestion if '<' not in sug]
|
| 48 |
-
feedback = f'\'{" ".join(suggestion)}\' might be a little better'
|
| 49 |
return feedback
|
| 50 |
|
| 51 |
iface = gr.Interface(
|
|
|
|
| 26 |
last_set_of_ids = history[len(history)-1][2]
|
| 27 |
bot_input_ids = torch.cat([last_set_of_ids, new_user_input_ids], dim=-1)
|
| 28 |
else:
|
|
|
|
| 29 |
bot_input_ids = new_user_input_ids
|
| 30 |
+
chat_history_ids = model.generate(bot_input_ids, max_length=5000, pad_token_id=tokenizer.eos_token_id)
|
| 31 |
response_ids = chat_history_ids[:, bot_input_ids.shape[-1]:][0]
|
| 32 |
response = tokenizer.decode(response_ids, skip_special_tokens=True)
|
| 33 |
history.append((message, response, chat_history_ids))
|
|
|
|
| 38 |
num_return_sequences=1
|
| 39 |
batch = grammar_tokenizer([text],truncation=True,padding='max_length',max_length=64, return_tensors="pt")
|
| 40 |
corrections= grammar_model.generate(**batch,max_length=64,num_beams=2, num_return_sequences=num_return_sequences, temperature=1.5)
|
| 41 |
+
corrected_text = tokenizer.decode(corrections[0], clean_up_tokenization_spaces=True, skip_special_tokens=True)
|
| 42 |
print("The corrections are: ", corrections)
|
| 43 |
+
if corrected_text == text:
|
| 44 |
feedback = f'Looks good! Keep up the good work'
|
| 45 |
else:
|
| 46 |
+
feedback = f'\'{" ".join(corrected_text)}\' might be a little better'
|
|
|
|
|
|
|
| 47 |
return feedback
|
| 48 |
|
| 49 |
iface = gr.Interface(
|