Update chatbot.py
Browse files- chatbot.py +0 -38
chatbot.py
CHANGED
@@ -17,44 +17,6 @@ def chat_with_model():
|
|
17 |
|
18 |
print(f"Bot: {answer} (confidence: {score:.2f})")
|
19 |
|
20 |
-
# Save chat function code in a script
|
21 |
-
with open('chatbot.py', 'w') as f:
|
22 |
-
f.write('''
|
23 |
-
from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering, pipeline
|
24 |
-
|
25 |
-
# Load tokenizer and model
|
26 |
-
tokenizer = AutoTokenizer.from_pretrained("my_awesome_qa_model")
|
27 |
-
model = TFAutoModelForQuestionAnswering.from_pretrained("my_awesome_qa_model")
|
28 |
-
|
29 |
-
# Create a pipeline for question answering
|
30 |
-
question_answerer = pipeline("question-answering", model=model, tokenizer=tokenizer)
|
31 |
-
|
32 |
-
# Define the chat function
|
33 |
-
def chat_with_model():
|
34 |
-
print("Welcome to the Question Answering Chatbot! (type 'exit' to quit)")
|
35 |
-
while True:
|
36 |
-
question = input("You: ")
|
37 |
-
if question.lower() == 'exit':
|
38 |
-
print("Goodbye!")
|
39 |
-
break
|
40 |
-
|
41 |
-
context = input("Context: ")
|
42 |
-
if context.lower() == 'exit':
|
43 |
-
print("Goodbye!")
|
44 |
-
break
|
45 |
-
|
46 |
-
response = question_answerer(question=question, context=context)
|
47 |
-
answer = response['answer']
|
48 |
-
score = response['score']
|
49 |
-
|
50 |
-
print(f"Bot: {answer} (confidence: {score:.2f})")
|
51 |
-
|
52 |
-
# Run the chat function
|
53 |
-
if __name__ == "__main__":
|
54 |
-
chat_with_model()
|
55 |
-
''')
|
56 |
-
|
57 |
-
print("Chatbot script 'chatbot.py' has been created.")
|
58 |
|
59 |
if __name__ == "__main__":
|
60 |
chat_with_model()
|
|
|
17 |
|
18 |
print(f"Bot: {answer} (confidence: {score:.2f})")
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
if __name__ == "__main__":
|
22 |
chat_with_model()
|