File size: 996 Bytes
a9c8f63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Replace with the model name you are using
model_name = "facebook/blenderbot-400M-distill"

# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# Function to generate bot response
def generate_response(user_input):
    inputs = tokenizer(user_input, return_tensors="pt")
    bot_output = model.generate(**inputs)
    bot_response = tokenizer.decode(bot_output[0], skip_special_tokens=True)
    return bot_response

# Example conversation flow
conversation_history = []

while True:
    user_input = input("User: ")
    conversation_history.append(user_input)

    if user_input.lower() == "exit":
        break

    bot_response = generate_response(user_input)
    conversation_history.append(f"Bot: {bot_response}")
    print(f"Bot: {bot_response}")

print("Updated Conversation History:", conversation_history)