File size: 706 Bytes
fd4bcdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from transformers import pipeline

# Load a pre-trained conversational model
chatbot = pipeline('conversational', model='microsoft/DialoGPT-medium')

def chat(user_input):
    # Convert user input to the format expected by the chatbot
    # For simplicity, we'll assume the model handles this internally
    response = chatbot(user_input)[0]['generated_text']
    return response

if __name__ == '__main__':
    print('Welcome to the Chatbot! Type 'exit' to end the conversation.')
    while True:
        user_input = input('You: ')
        if user_input.lower() == 'exit':
            print('Chatbot: Goodbye!')
            break
        response = chat(user_input)
        print(f'Chatbot: {response}')}