MidPlus / app.py
underwater45's picture
Rename main (2).py to app.py
0e01963
import json
class MidPlusV2:
def __init__(self):
self.name = "MidPlus V2"
self.predefined_responses = {
"How are you?": "I'm just a chatbot, but I'm doing well!",
"What's the weather like?": "I'm not sure about the weather, but I'm here to chat!",
"Tell me a joke": "Why did the computer catch a cold? It had too many windows open!",
"Who won the World Series in 2020?": "The Los Angeles Dodgers won the World Series in 2020.",
"What's your favorite color?": "I don't have a favorite color, but I like all colors!",
"What's the meaning of life?": "The meaning of life is a philosophical question with no definitive answer.",
"How tall is Mount Everest?": "Mount Everest is approximately 29,032 feet (8,849 meters) tall.",
"What's the capital of France?": "The capital of France is Paris.",
"How many continents are there?": "There are seven continents on Earth.",
"What's the largest planet in our solar system?": "Jupiter is the largest planet in our solar system.",
"What's the national flower of Japan?": "The national flower of Japan is the cherry blossom.",
"What's the square root of 144?": "The square root of 144 is 12.",
"Who wrote the play 'Romeo and Juliet'?": "William Shakespeare wrote the play 'Romeo and Juliet'.",
"What's the atomic number of carbon?": "The atomic number of carbon is 6.",
"What's the largest mammal in the world?": "The blue whale is the largest mammal in the world.",
"What's the fastest land animal?": "The cheetah is the fastest land animal.",
"What's the most abundant gas in Earth's atmosphere?": "Nitrogen is the most abundant gas in Earth's atmosphere.",
"What's the largest ocean on Earth?": "The Pacific Ocean is the largest ocean on Earth.",
"What's the chemical symbol for gold?": "The chemical symbol for gold is Au.",
"What's the freezing point of water in Fahrenheit?": "The freezing point of water in Fahrenheit is 32 degrees.",
"What's the boiling point of water in Celsius?": "The boiling point of water in Celsius is 100 degrees.",
"Who painted the Mona Lisa?": "Leonardo da Vinci painted the Mona Lisa.",
"What's the largest desert in the world?": "The Sahara Desert is the largest desert in the world.",
"What's the national animal of Australia?": "The national animal of Australia is the kangaroo.",
"What's the smallest prime number?": "The smallest prime number is 2.",
"What's the highest mountain in North America?": "Denali (formerly known as Mount McKinley) is the highest mountain in North America.",
"What's the most widely spoken language in the world?": "Mandarin Chinese is the most widely spoken language in the world.",
"What's the largest species of shark?": "The whale shark is the largest species of shark.",
"What's the chemical symbol for oxygen?": "The chemical symbol for oxygen is O.",
"Who wrote the novel '1984'?": "George Orwell wrote the novel '1984'.",
"What's the national flower of the United States?": "The national flower of the United States is the rose.",
"What's the smallest planet in our solar system?": "Mercury is the smallest planet in our solar system.",
"What's the capital of Brazil?": "The capital of Brazil is Brasília.",
"What's the symbol for the element hydrogen?": "The symbol for the element hydrogen is H.",
"What's the largest species of penguin?": "The Emperor penguin is the largest species of penguin.",
"What's the distance from the Earth to the Moon?": "The average distance from the Earth to the Moon is about 238,855 miles (384,400 kilometers).",
"What's the largest bird in the world?": "The ostrich is the largest bird in the world.",
# Your predefined responses here
}
self.knowledge_base = {}
self.load_knowledge()
def answer_question(self, question):
if question in self.predefined_responses:
return self.predefined_responses[question]
if question in self.knowledge_base:
return self.knowledge_base[question]
return "I'm not sure how to answer that. Can you provide an answer?"
def add_answer(self, question, answer):
self.knowledge_base[question] = answer
self.save_knowledge()
def load_knowledge(self):
try:
with open("knowledge_base.json", "r") as file:
self.knowledge_base = json.load(file)
except FileNotFoundError:
self.knowledge_base = {}
def save_knowledge(self):
with open("knowledge_base.json", "w") as file:
json.dump(self.knowledge_base, file)
midplus_v2 = MidPlusV2()
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
break # Exit the loop if the user enters "exit"
response = midplus_v2.answer_question(user_input)
print(f"MidPlus V2: {response}")
if response == "I'm not sure how to answer that. Can you provide an answer?":
user_answer = input("You can provide an answer: ")
if user_answer:
midplus_v2.add_answer(user_input, user_answer)
print(f"Thanks for teaching me! I'll remember that: {user_answer}")