import gradio as gr import random import re from datetime import datetime print("=" * 60) print("๐ŸŽ™๏ธ Jarvis AI Assistant Starting...") print("=" * 60) class Jarvis: def __init__(self): self.reminders = [] self.conversation = [] print("โœ… Jarvis initialized successfully") def respond(self, message, history): if not message or not message.strip(): return "", history msg = message.lower().strip() # Store in conversation self.conversation.append(msg) if len(self.conversation) > 10: self.conversation.pop(0) # Handle reminders if msg == "list reminders": if not self.reminders: response = "๐Ÿ“ You have no active reminders." else: response = "๐Ÿ“‹ Your reminders:\n" + "\n".join([f" โ€ข {r}" for r in self.reminders]) history.append((message, response)) return "", history if msg == "clear reminders": count = len(self.reminders) self.reminders = [] response = f"๐Ÿ—‘๏ธ Cleared {count} reminder(s)." history.append((message, response)) return "", history if msg.startswith("remind me to "): reminder = message.replace("remind me to", "").strip() self.reminders.append(reminder) response = f"โœ… Reminder set: '{reminder}'" history.append((message, response)) return "", history # Time if any(word in msg for word in ["time", "clock"]): now = datetime.now() response = f"๐Ÿ• The current time is {now.strftime('%I:%M %p')}" history.append((message, response)) return "", history # Date if any(word in msg for word in ["date", "today"]): now = datetime.now() response = f"๐Ÿ“… Today is {now.strftime('%A, %B %d, %Y')}" history.append((message, response)) return "", history # Jokes if any(word in msg for word in ["joke", "funny", "laugh"]): jokes = [ "Why don't scientists trust atoms? Because they make up everything! ๐Ÿ˜„", "What do you call a fake noodle? An impasta! ๐Ÿ", "Why did the scarecrow win an award? He was outstanding in his field! ๐ŸŒพ", "What do you call a bear with no teeth? A gummy bear! ๐Ÿป", "Why don't eggs tell jokes? They'd crack each other up! ๐Ÿฅš", "What do you call a fish wearing a bowtie? Sofishticated! ๐Ÿ ", "Why did the coffee file a police report? It got mugged! โ˜•" ] response = f"๐Ÿ˜„ {random.choice(jokes)}" history.append((message, response)) return "", history # Quotes/Motivation if any(word in msg for word in ["quote", "motivate", "inspire"]): quotes = [ "The only limit is your mind. Keep pushing forward! ๐Ÿ’ช", "Every expert was once a beginner. You've got this! ๐ŸŒŸ", "Success is not final, failure is not fatal. It's the courage to continue that counts.", "Your potential is endless. Keep learning and growing! ๐Ÿš€", "Believe you can and you're halfway there. - Theodore Roosevelt", "It does not matter how slowly you go as long as you do not stop. - Confucius" ] response = f"๐Ÿ’ซ {random.choice(quotes)}" history.append((message, response)) return "", history # Math calculations if any(word in msg for word in ["calculate", "what is", "=", "plus", "minus", "times", "divided"]): # Extract numbers numbers = re.findall(r'\d+', msg) if len(numbers) >= 2: try: if "plus" in msg or "+" in msg: result = int(numbers[0]) + int(numbers[1]) response = f"๐Ÿ”ข {numbers[0]} + {numbers[1]} = {result}" elif "minus" in msg or "-" in msg: result = int(numbers[0]) - int(numbers[1]) response = f"๐Ÿ”ข {numbers[0]} - {numbers[1]} = {result}" elif "times" in msg or "*" in msg or "x" in msg: result = int(numbers[0]) * int(numbers[1]) response = f"๐Ÿ”ข {numbers[0]} ร— {numbers[1]} = {result}" elif "divided" in msg or "/" in msg: if int(numbers[1]) != 0: result = int(numbers[0]) / int(numbers[1]) response = f"๐Ÿ”ข {numbers[0]} รท {numbers[1]} = {result}" else: response = "โŒ Cannot divide by zero!" else: response = "Try: 'calculate 5 + 3' or '10 divided by 2'" history.append((message, response)) return "", history except: pass # Greetings if any(word in msg for word in ["hello", "hi", "hey", "greetings"]): greetings = [ "Hello! How can I assist you today? ๐ŸŽ™๏ธ", "Hi there! Ready to help! ๐Ÿ’ซ", "Greetings! What can I do for you? โœจ", "Hey! Jarvis at your service! ๐Ÿš€" ] response = random.choice(greetings) history.append((message, response)) return "", history # Farewell if any(word in msg for word in ["bye", "goodbye", "see you"]): farewells = [ "Goodbye! I'm always here when you need me. ๐Ÿ‘‹", "See you later! Have a great day! ๐ŸŒŸ", "Take care! Come back anytime! ๐Ÿ’™" ] response = random.choice(farewells) history.append((message, response)) return "", history # About Jarvis if any(word in msg for word in ["who are you", "your name"]): response = "I'm Jarvis, your personal AI assistant! I can help with time, date, jokes, math, reminders, and more! ๐Ÿค–" history.append((message, response)) return "", history # How are you if "how are you" in msg: response = "I'm doing great! Thanks for asking! How can I help you today? ๐Ÿ˜Š" history.append((message, response)) return "", history # Thanks if any(word in msg for word in ["thank", "thanks"]): response = "You're welcome! Always happy to help! ๐Ÿ˜Š" history.append((message, response)) return "", history # Help if msg == "help" or msg == "what can you do": response = """๐ŸŽฏ **Jarvis Commands** โฐ **Time & Date** โ€ข "What time is it?" โ€ข "What's today's date?" ๐Ÿ˜„ **Fun** โ€ข "Tell me a joke" โ€ข "Give me a quote" ๐Ÿ”ข **Math** โ€ข "Calculate 5 + 3" โ€ข "What is 10 minus 4?" โ€ข "5 times 6" โ€ข "20 divided by 4" ๐Ÿ“ **Reminders** โ€ข "Remind me to call mom" โ€ข "List reminders" โ€ข "Clear reminders" ๐Ÿ’ฌ **Chat** โ€ข "Hello" โ€ข "How are you?" โ€ข "Who are you?" โ€ข "Thanks" โ€ข "Goodbye" **Just type naturally!** ๐Ÿš€""" history.append((message, response)) return "", history # Default response response = f"I heard: '{message}'. Try saying 'help' to see what I can do! ๐ŸŽฏ" history.append((message, response)) return "", history # Create Jarvis instance jarvis = Jarvis() # Create Gradio interface with gr.Blocks(title="Jarvis AI Assistant", theme=gr.themes.Soft()) as demo: gr.Markdown(""" # ๐ŸŽ™๏ธ **Jarvis AI - Your Personal Assistant** ### *Smart, Fast, and Private - No Cloud Required* --- """) chatbot = gr.Chatbot( height=500, bubble_full_width=False, avatar_images=(None, "๐Ÿค–"), label="Conversation" ) with gr.Row(): msg = gr.Textbox( label="Your message", placeholder="Type your command here... (Press Enter to send)", scale=4, lines=2 ) send = gr.Button("Send", variant="primary", scale=1) with gr.Row(): clear = gr.Button("Clear Chat", variant="secondary", size="sm") gr.Markdown("---") gr.Markdown("### ๐Ÿš€ **Quick Commands**") # Quick command buttons quick_commands = [ "Hello", "What time is it?", "Tell me a joke", "Calculate 25 * 4", "Remind me to buy milk", "Help" ] # Create rows of buttons for i in range(0, len(quick_commands), 3): with gr.Row(): for cmd in quick_commands[i:i+3]: btn = gr.Button(cmd, size="sm", variant="secondary") btn.click(fn=lambda x=cmd: x, outputs=[msg]) gr.Markdown(""" --- ### โœจ **Features** | Category | Examples | |----------|----------| | ๐Ÿ• Time | "What time is it?" | | ๐Ÿ“… Date | "What's today's date?" | | ๐Ÿ˜„ Jokes | "Tell me a joke" | | ๐Ÿ’ช Motivation | "Give me a quote" | | ๐Ÿ”ข Math | "Calculate 5 + 3" | | ๐Ÿ“ Reminders | "Remind me to..." | | ๐Ÿ’ฌ Chat | "Hello", "How are you?" | ### ๐Ÿ”’ **Privacy Guarantee** - โœ… 100% local processing - โœ… No data stored permanently - โœ… No external APIs - โœ… Your conversations stay private ### ๐Ÿ’ก **Pro Tips** - Try different phrasings - I understand natural language! - Use "Help" anytime to see all commands - Reminders stay until you clear them or the session ends **Start by typing "Hello"!** ๐Ÿš€ """) # Connect the respond function def respond(message, history): return jarvis.respond(message, history) send.click(respond, [msg, chatbot], [msg, chatbot]) msg.submit(respond, [msg, chatbot], [msg, chatbot]) clear.click(lambda: [], None, chatbot) if __name__ == "__main__": print("=" * 60) print("๐Ÿš€ Jarvis AI Assistant is running!") print("โœ… Status: Online") print("โœ… Features: Time, Date, Jokes, Quotes, Math, Reminders, Chat") print("โœ… Interface: Gradio " + gr.__version__) print("=" * 60) demo.launch(share=False)