File size: 10,634 Bytes
4e0ed9b
 
 
 
8be6713
bd113aa
 
 
68652ee
3e30069
4e0ed9b
 
c3e4137
 
bd113aa
c3e4137
bd113aa
c3e4137
4e0ed9b
bd113aa
4e0ed9b
c3e4137
 
 
 
 
 
bd113aa
 
c3e4137
 
 
 
 
4e0ed9b
bd113aa
 
 
c3e4137
 
 
4e0ed9b
bd113aa
 
 
c3e4137
 
 
3e30069
bd113aa
 
3e30069
c3e4137
 
 
3e30069
bd113aa
 
3e30069
c3e4137
 
 
3e30069
bd113aa
 
3e30069
bd113aa
 
 
 
c3e4137
 
 
4e0ed9b
c3e4137
 
 
3e30069
c3e4137
bd113aa
3e30069
 
 
 
c3e4137
 
 
3e30069
c3e4137
 
 
bd113aa
c3e4137
 
 
bd113aa
 
 
 
 
c3e4137
bd113aa
 
c3e4137
bd113aa
 
c3e4137
bd113aa
 
 
c3e4137
bd113aa
c3e4137
 
 
 
 
bd113aa
 
 
 
 
c3e4137
bd113aa
 
c3e4137
 
 
 
 
 
bd113aa
 
 
c3e4137
bd113aa
 
 
c3e4137
 
 
 
bd113aa
c3e4137
bd113aa
c3e4137
 
 
bd113aa
 
 
c3e4137
 
 
4e0ed9b
bd113aa
 
c3e4137
 
 
4e0ed9b
bd113aa
 
c3e4137
4e0ed9b
3e30069
bd113aa
 
4e0ed9b
3e30069
bd113aa
 
4e0ed9b
3e30069
bd113aa
 
 
 
4e0ed9b
3e30069
bd113aa
 
 
4e0ed9b
3e30069
bd113aa
 
 
 
 
4e0ed9b
bd113aa
c3e4137
 
 
 
 
 
 
4e0ed9b
bd113aa
 
4e0ed9b
c3e4137
3e30069
c3e4137
4e0ed9b
bd113aa
4e0ed9b
c3e4137
4e0ed9b
 
 
 
c3e4137
 
 
 
 
 
4e0ed9b
bd113aa
 
 
 
 
 
 
 
4e0ed9b
 
c3e4137
4e0ed9b
 
bd113aa
4e0ed9b
c3e4137
bd113aa
 
 
 
4e0ed9b
c3e4137
bd113aa
 
 
 
 
4e0ed9b
 
 
bd113aa
 
c3e4137
 
bd113aa
c3e4137
bd113aa
 
 
 
 
 
 
 
c3e4137
bd113aa
 
 
c3e4137
 
 
 
 
bd113aa
4e0ed9b
 
c3e4137
 
 
bd113aa
 
 
 
4e0ed9b
 
bd113aa
c3e4137
 
 
 
bd113aa
4e0ed9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
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)