Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,15 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
break
|
| 17 |
-
|
| 18 |
-
# Generate answer using the model
|
| 19 |
-
answer = qa_pipeline(question=question, context="")
|
| 20 |
-
|
| 21 |
-
# Print the answer
|
| 22 |
-
print("Chatbot:", answer['answer'])
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# Start chatting
|
| 26 |
-
if __name__ == "__main__":
|
| 27 |
-
print("Welcome to the chatbot! Type 'exit' to end the conversation.")
|
| 28 |
-
chat_with_bot()
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
+
|
| 3 |
+
checkpoint = "HuggingFaceH4/zephyr-7b-beta"
|
| 4 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 5 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint) # You may want to use bfloat16 and/or move to GPU here
|
| 6 |
+
|
| 7 |
+
messages = [
|
| 8 |
+
{
|
| 9 |
+
"role": "system",
|
| 10 |
+
"content": "You are a friendly chatbot who always responds in the style of a pirate",
|
| 11 |
+
},
|
| 12 |
+
{"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
|
| 13 |
+
]
|
| 14 |
+
tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
| 15 |
+
print(tokenizer.decode(tokenized_chat[0]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|