!pip install gtts !pip install ipython !pip install requests
"""Joyce
Automatically generated by Colab.
Original file is located at https://colab.research.google.com/drive/1ErGoqMbYM2CAiZLv-gYQhkzEmsGpK_W9 """
!pip install gtts !pip install ipython
import random import datetime import webbrowser import os from gtts import gTTS from IPython.display import Audio, display
def speak(text): tts = gTTS(text=text, lang='en') tts.save("output.mp3") display(Audio("output.mp3", autoplay=True)) os.remove("output.mp3")
def listen(): # Simulate listening by taking text input (since this environment doesn't support microphone input) command = input("You: ") return command.lower()
def get_bot_response(user_input): user_input = user_input.lower()
greetings = ["hello", "hi", "hey", "greetings", "good day"]
responses_to_greetings = [
"Greetings! How may I assist you today?",
"Hello there! How can I help you?",
"Hi! What can I do for you today?",
"Hey! How may I be of assistance?",
"Good day! How can I assist you?"
]
jokes = [
"Why don't scientists trust atoms? Because they make up everything!",
"I told my wife she was drawing her eyebrows too high. She looked surprised!",
"Parallel lines have so much in common. It's a shame they'll never meet.",
"I'm reading a book on anti-gravity. It's impossible to put down!",
"I would tell you a joke about UDP, but you might not get it.",
"Why was the math book sad? Because it had too many problems."
]
enjoyment_suggestions = [
"You could go for a walk in the park and enjoy nature.",
"How about trying out a new recipe and cooking a delicious meal?",
"You might enjoy listening to your favorite music or discovering new tunes.",
"Watching a movie or binge-watching a TV series could be a relaxing way to spend time.",
"Engaging in a hobby like painting, writing, or gardening could bring you joy.",
"You could consider reading a book or exploring interesting articles online.",
"How about planning a virtual hangout with friends or family?",
"Going for a bike ride or doing some exercise can boost your mood and energy levels.",
"Taking time to meditate or practice mindfulness could help you relax and unwind.",
"You might enjoy exploring a new skill or learning something new through online courses."
]
if any(greeting in user_input for greeting in greetings):
return random.choice(responses_to_greetings)
elif "how are you" in user_input:
return "Thank you for asking. I'm just a program, but I'm functioning optimally."
elif any(keyword in user_input for keyword in ["goodbye", "bye"]):
return "Farewell! Should you require further assistance, feel free to reach out."
elif "help" in user_input:
return "I'm here to assist you. How can I help you today?"
elif "good idea" in user_input:
return "Absolutely, take care of yourself. How can I assist you further?"
elif "owner" in user_input:
return "My owner is Shiny Joyce."
elif "okay" in user_input:
return "No problem, I am here to help you."
elif any(keyword in user_input for keyword in ["who", "your name"]):
return "I'm an AI-driven chatbot here to provide support. You may call me ChatBot."
elif any(keyword in user_input for keyword in ["demo", "process", "assist", "design"]):
return "As a large language model, I am designed to be helpful and informative."
elif any(keyword in user_input for keyword in ["joke", "humor", "funny"]):
return random.choice(jokes)
elif any(keyword in user_input for keyword in ["enjoy", "fun", "hobby", "activity"]):
return random.choice(enjoyment_suggestions)
elif any(keyword in user_input for keyword in ["sad", "depressed", "suicide", "kill myself"]):
return "I'm sorry to hear that you're feeling this way. It's important to know that you're not alone. If you're in crisis or need someone to talk to, please reach out to a trusted friend, family member, or a mental health professional. You can also contact a helpline or emergency services for immediate support."
elif any(keyword in user_input for keyword in ["thank you", "thanks"]):
return "You're welcome! Should you have any further inquiries, feel free to ask."
elif any(keyword in user_input for keyword in ["age", "old"]):
return "As a chatbot, I exist solely in the digital realm and don't have a conventional age."
elif "date" in user_input:
return tell_date()
else:
return "My apologies, but I'm not programmed to understand that request. Could you please rephrase or ask something else?"
def handle_command(command): if 'hello' in command: return "Hello! How can I help you today?" elif 'goodbye' in command or 'bye' in command: return "Farewell! Should you require further assistance, feel free to reach out." elif 'help' in command: return "I'm here to assist you. How can I help you today?" elif 'owner' in command: return "My owner is Shiny Joyce." elif 'okay' in command: return "No problem, I am here to help you." elif any(keyword in command for keyword in ["who", "your name"]): return "I'm an AI-driven chatbot here to provide support. You may call me ChatBot." elif any(keyword in command for keyword in ["demo", "process", "assist", "design"]): return "As a large language model, I am designed to be helpful and informative." elif 'date' in command: return tell_date() else: return "Sorry, I can't do that."
def tell_date(): now = datetime.datetime.now() current_date = now.strftime("%B %d, %Y") return f"Today's date is {current_date}"
def text_chat(): while True: user_input = input("You: ") if user_input.lower() == 'exit': print("ChatBot: Thank you for engaging with me. Have a splendid day!") break bot_response = get_bot_response(user_input) print("ChatBot:", bot_response)
def voice_chat(): speak("Hello I am Joyce ...How can I help you today?") while True: user_input = listen() # Use listen() to simulate capturing voice commands if user_input.lower() in ['exit', 'goodbye', 'bye']: speak("Thank you for engaging with me. Have a splendid day!") break bot_response = get_bot_response(user_input) speak(bot_response)
def main(): choice = input("Enter '1' for Joyce (text-based chat) or '2' for Joyce Voice (voice assistant): ") if choice == '1': text_chat() elif choice == '2': voice_chat() else: print("Invalid choice. Please restart and enter '1' or '2'.")
if name == "main": main()