Created
November 6, 2023 20:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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