Skip to content

Instantly share code, notes, and snippets.

@magician11
Created November 6, 2023 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magician11/5d99041cf2caf31ddf36802ef5e98450 to your computer and use it in GitHub Desktop.
Save magician11/5d99041cf2caf31ddf36802ef5e98450 to your computer and use it in GitHub Desktop.
How to create a chat app running locally on a laptop using a Hugging Face model
import time
from transformers import pipeline, Conversation
model_name = "facebook/blenderbot-400M-distill"
start = time.time()
converse = pipeline("conversational", model=model_name)
print(f"Model loaded. Time taken: {time.time() - start} seconds")
conversation = Conversation()
while True:
user_input = input("You: ")
if user_input.lower() == "quit":
break
start = time.time()
conversation.add_user_input(user_input)
response = converse([conversation])
print(f"Bot: {response.generated_responses[-1]}")
print(f"Response received. Time taken: {time.time() - start} seconds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment