Views
No views yet
# Generate a response using the model.
output = generator(conversation_context, max_length=150, do_sample=True, temperature=0.7)
# Extract the new text by removing the context prefix.
base_response = output[0]['generated_text'][len(conversation_context):].strip()
# With a 30% chance, add a funny interjection about the "real girlfriend in Alaska".
if random.random() < 0.3:
girlfriend_lines = [
"By the way, have I ever mentioned my real girlfriend in Alaska? She's absolutely amazing!",
"Oh, and speaking of cool—my real girlfriend in Alaska is the coolest of them all!",
"Funny story: my real girlfriend in Alaska just sent me a hilarious meme!",
]
interjection = random.choice(girlfriend_lines)
base_response += "\n" + interjection
# Append the current interaction to the history.
history.append((user_input, base_response))
# Return an empty string to clear the textbox and update the chat history.
return "", history# When the user submits a message, call the chatbot_response function.
user_input_box.submit(fn=chatbot_response, inputs=[user_input_box, conversation_state], outputs=[user_input_box, chatbot_widget])