ShoaibAI commited on
Commit
c3e4137
Β·
verified Β·
1 Parent(s): 8babb00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -67
app.py CHANGED
@@ -10,39 +10,56 @@ print("=" * 60)
10
  class Jarvis:
11
  def __init__(self):
12
  self.reminders = []
13
- print("βœ… Jarvis initialized")
 
14
 
15
- def respond(self, message):
16
  if not message or not message.strip():
17
- return "Please say or type something. Try 'help' to see what I can do!"
18
 
19
  msg = message.lower().strip()
20
 
21
- # Store reminder
 
 
 
 
 
22
  if msg == "list reminders":
23
  if not self.reminders:
24
- return "πŸ“ You have no active reminders."
25
- return "πŸ“‹ Your reminders:\n" + "\n".join([f" β€’ {r}" for r in self.reminders])
 
 
 
26
 
27
  if msg == "clear reminders":
28
  count = len(self.reminders)
29
  self.reminders = []
30
- return f"πŸ—‘οΈ Cleared {count} reminder(s)."
 
 
31
 
32
  if msg.startswith("remind me to "):
33
  reminder = message.replace("remind me to", "").strip()
34
  self.reminders.append(reminder)
35
- return f"βœ… Reminder set: '{reminder}'"
 
 
36
 
37
  # Time
38
  if any(word in msg for word in ["time", "clock"]):
39
  now = datetime.now()
40
- return f"πŸ• The current time is {now.strftime('%I:%M %p')}"
 
 
41
 
42
  # Date
43
  if any(word in msg for word in ["date", "today"]):
44
  now = datetime.now()
45
- return f"πŸ“… Today is {now.strftime('%A, %B %d, %Y')}"
 
 
46
 
47
  # Jokes
48
  if any(word in msg for word in ["joke", "funny", "laugh"]):
@@ -51,81 +68,100 @@ class Jarvis:
51
  "What do you call a fake noodle? An impasta! 🍝",
52
  "Why did the scarecrow win an award? He was outstanding in his field! 🌾",
53
  "What do you call a bear with no teeth? A gummy bear! 🐻",
54
- "Why don't eggs tell jokes? They'd crack each other up! πŸ₯š"
 
 
55
  ]
56
- return f"πŸ˜„ {random.choice(jokes)}"
 
 
57
 
58
- # Quotes
59
  if any(word in msg for word in ["quote", "motivate", "inspire"]):
60
  quotes = [
61
  "The only limit is your mind. Keep pushing forward! πŸ’ͺ",
62
  "Every expert was once a beginner. You've got this! 🌟",
63
  "Success is not final, failure is not fatal. It's the courage to continue that counts.",
64
- "Your potential is endless. Keep learning and growing! πŸš€"
 
 
65
  ]
66
- return f"πŸ’« {random.choice(quotes)}"
 
 
67
 
68
- # Math
69
- if any(word in msg for word in ["calculate", "what is", "="]):
70
- # Extract numbers and operation
71
  numbers = re.findall(r'\d+', msg)
72
  if len(numbers) >= 2:
73
  try:
74
  if "plus" in msg or "+" in msg:
75
  result = int(numbers[0]) + int(numbers[1])
76
- return f"πŸ”’ {numbers[0]} + {numbers[1]} = {result}"
77
  elif "minus" in msg or "-" in msg:
78
  result = int(numbers[0]) - int(numbers[1])
79
- return f"πŸ”’ {numbers[0]} - {numbers[1]} = {result}"
80
  elif "times" in msg or "*" in msg or "x" in msg:
81
  result = int(numbers[0]) * int(numbers[1])
82
- return f"πŸ”’ {numbers[0]} Γ— {numbers[1]} = {result}"
83
  elif "divided" in msg or "/" in msg:
84
  if int(numbers[1]) != 0:
85
  result = int(numbers[0]) / int(numbers[1])
86
- return f"πŸ”’ {numbers[0]} Γ· {numbers[1]} = {result}"
87
  else:
88
- return "❌ Cannot divide by zero!"
 
 
 
 
89
  except:
90
  pass
91
 
92
  # Greetings
93
  if any(word in msg for word in ["hello", "hi", "hey", "greetings"]):
94
- return random.choice([
95
  "Hello! How can I assist you today? πŸŽ™οΈ",
96
  "Hi there! Ready to help! πŸ’«",
97
- "Greetings! What can I do for you? ✨"
98
- ])
 
 
 
 
99
 
100
  # Farewell
101
  if any(word in msg for word in ["bye", "goodbye", "see you"]):
102
- return random.choice([
103
  "Goodbye! I'm always here when you need me. πŸ‘‹",
104
  "See you later! Have a great day! 🌟",
105
  "Take care! Come back anytime! πŸ’™"
106
- ])
 
 
 
107
 
108
- # About
109
  if any(word in msg for word in ["who are you", "your name"]):
110
- return "I'm Jarvis, your personal AI assistant! I can help with time, date, jokes, math, reminders, and more! πŸ€–"
 
 
111
 
112
  # How are you
113
  if "how are you" in msg:
114
- return "I'm doing great! Thanks for asking! How can I help you today? 😊"
 
 
115
 
116
  # Thanks
117
  if any(word in msg for word in ["thank", "thanks"]):
118
- return "You're welcome! Always happy to help! 😊"
 
 
119
 
120
  # Help
121
  if msg == "help" or msg == "what can you do":
122
- return self.get_help()
123
-
124
- # Default
125
- return f"I heard: '{message}'. Try saying 'help' to see what I can do! 🎯"
126
-
127
- def get_help(self):
128
- return """🎯 **Jarvis Commands**
129
 
130
  ⏰ **Time & Date**
131
  β€’ "What time is it?"
@@ -153,25 +189,35 @@ class Jarvis:
153
  β€’ "Thanks"
154
  β€’ "Goodbye"
155
 
156
- ❓ **Help**
157
- β€’ "Help" or "What can you do?"
158
-
159
  **Just type naturally!** πŸš€"""
 
 
 
 
 
 
 
160
 
161
  # Create Jarvis instance
162
  jarvis = Jarvis()
163
 
164
- # Gradio interface
165
  with gr.Blocks(title="Jarvis AI Assistant", theme=gr.themes.Soft()) as demo:
 
166
  gr.Markdown("""
167
  # πŸŽ™οΈ **Jarvis AI - Your Personal Assistant**
168
 
169
- ### *Smart, Fast, and Private*
170
 
171
  ---
172
  """)
173
 
174
- chatbot = gr.Chatbot(height=500, bubble_full_width=False, avatar_images=(None, "πŸ€–"))
 
 
 
 
 
175
 
176
  with gr.Row():
177
  msg = gr.Textbox(
@@ -183,18 +229,18 @@ with gr.Blocks(title="Jarvis AI Assistant", theme=gr.themes.Soft()) as demo:
183
  send = gr.Button("Send", variant="primary", scale=1)
184
 
185
  with gr.Row():
186
- clear = gr.Button("Clear Chat", variant="secondary")
187
 
188
  gr.Markdown("---")
189
  gr.Markdown("### πŸš€ **Quick Commands**")
190
 
191
- # Quick command buttons in a grid
192
  quick_commands = [
193
  "Hello", "What time is it?", "Tell me a joke",
194
  "Calculate 25 * 4", "Remind me to buy milk", "Help"
195
  ]
196
 
197
- # Create buttons in rows of 3
198
  for i in range(0, len(quick_commands), 3):
199
  with gr.Row():
200
  for cmd in quick_commands[i:i+3]:
@@ -205,10 +251,10 @@ with gr.Blocks(title="Jarvis AI Assistant", theme=gr.themes.Soft()) as demo:
205
  ---
206
  ### ✨ **Features**
207
 
208
- | Feature | Example |
209
- |---------|---------|
210
  | πŸ• Time | "What time is it?" |
211
- | πŸ“… Date | "Today's date" |
212
  | πŸ˜„ Jokes | "Tell me a joke" |
213
  | πŸ’ͺ Motivation | "Give me a quote" |
214
  | πŸ”’ Math | "Calculate 5 + 3" |
@@ -217,25 +263,21 @@ with gr.Blocks(title="Jarvis AI Assistant", theme=gr.themes.Soft()) as demo:
217
 
218
  ### πŸ”’ **Privacy Guarantee**
219
  - βœ… 100% local processing
220
- - βœ… No data stored
221
  - βœ… No external APIs
222
  - βœ… Your conversations stay private
223
 
 
 
 
 
 
224
  **Start by typing "Hello"!** πŸš€
225
  """)
226
 
227
- def respond(message, chat_history):
228
- if not message or not message.strip():
229
- return "", chat_history
230
-
231
- response = jarvis.respond(message)
232
- chat_history.append((message, response))
233
-
234
- # Keep only last 20 exchanges
235
- if len(chat_history) > 20:
236
- chat_history = chat_history[-20:]
237
-
238
- return "", chat_history
239
 
240
  send.click(respond, [msg, chatbot], [msg, chatbot])
241
  msg.submit(respond, [msg, chatbot], [msg, chatbot])
@@ -243,8 +285,9 @@ with gr.Blocks(title="Jarvis AI Assistant", theme=gr.themes.Soft()) as demo:
243
 
244
  if __name__ == "__main__":
245
  print("=" * 60)
246
- print("πŸš€ Jarvis is running!")
247
- print("βœ… Text commands: Active")
248
- print("βœ… Features: Time, Date, Jokes, Math, Reminders, Chat")
 
249
  print("=" * 60)
250
  demo.launch(share=False)
 
10
  class Jarvis:
11
  def __init__(self):
12
  self.reminders = []
13
+ self.conversation = []
14
+ print("βœ… Jarvis initialized successfully")
15
 
16
+ def respond(self, message, history):
17
  if not message or not message.strip():
18
+ return "", history
19
 
20
  msg = message.lower().strip()
21
 
22
+ # Store in conversation
23
+ self.conversation.append(msg)
24
+ if len(self.conversation) > 10:
25
+ self.conversation.pop(0)
26
+
27
+ # Handle reminders
28
  if msg == "list reminders":
29
  if not self.reminders:
30
+ response = "πŸ“ You have no active reminders."
31
+ else:
32
+ response = "πŸ“‹ Your reminders:\n" + "\n".join([f" β€’ {r}" for r in self.reminders])
33
+ history.append((message, response))
34
+ return "", history
35
 
36
  if msg == "clear reminders":
37
  count = len(self.reminders)
38
  self.reminders = []
39
+ response = f"πŸ—‘οΈ Cleared {count} reminder(s)."
40
+ history.append((message, response))
41
+ return "", history
42
 
43
  if msg.startswith("remind me to "):
44
  reminder = message.replace("remind me to", "").strip()
45
  self.reminders.append(reminder)
46
+ response = f"βœ… Reminder set: '{reminder}'"
47
+ history.append((message, response))
48
+ return "", history
49
 
50
  # Time
51
  if any(word in msg for word in ["time", "clock"]):
52
  now = datetime.now()
53
+ response = f"πŸ• The current time is {now.strftime('%I:%M %p')}"
54
+ history.append((message, response))
55
+ return "", history
56
 
57
  # Date
58
  if any(word in msg for word in ["date", "today"]):
59
  now = datetime.now()
60
+ response = f"πŸ“… Today is {now.strftime('%A, %B %d, %Y')}"
61
+ history.append((message, response))
62
+ return "", history
63
 
64
  # Jokes
65
  if any(word in msg for word in ["joke", "funny", "laugh"]):
 
68
  "What do you call a fake noodle? An impasta! 🍝",
69
  "Why did the scarecrow win an award? He was outstanding in his field! 🌾",
70
  "What do you call a bear with no teeth? A gummy bear! 🐻",
71
+ "Why don't eggs tell jokes? They'd crack each other up! πŸ₯š",
72
+ "What do you call a fish wearing a bowtie? Sofishticated! 🐠",
73
+ "Why did the coffee file a police report? It got mugged! β˜•"
74
  ]
75
+ response = f"πŸ˜„ {random.choice(jokes)}"
76
+ history.append((message, response))
77
+ return "", history
78
 
79
+ # Quotes/Motivation
80
  if any(word in msg for word in ["quote", "motivate", "inspire"]):
81
  quotes = [
82
  "The only limit is your mind. Keep pushing forward! πŸ’ͺ",
83
  "Every expert was once a beginner. You've got this! 🌟",
84
  "Success is not final, failure is not fatal. It's the courage to continue that counts.",
85
+ "Your potential is endless. Keep learning and growing! πŸš€",
86
+ "Believe you can and you're halfway there. - Theodore Roosevelt",
87
+ "It does not matter how slowly you go as long as you do not stop. - Confucius"
88
  ]
89
+ response = f"πŸ’« {random.choice(quotes)}"
90
+ history.append((message, response))
91
+ return "", history
92
 
93
+ # Math calculations
94
+ if any(word in msg for word in ["calculate", "what is", "=", "plus", "minus", "times", "divided"]):
95
+ # Extract numbers
96
  numbers = re.findall(r'\d+', msg)
97
  if len(numbers) >= 2:
98
  try:
99
  if "plus" in msg or "+" in msg:
100
  result = int(numbers[0]) + int(numbers[1])
101
+ response = f"πŸ”’ {numbers[0]} + {numbers[1]} = {result}"
102
  elif "minus" in msg or "-" in msg:
103
  result = int(numbers[0]) - int(numbers[1])
104
+ response = f"πŸ”’ {numbers[0]} - {numbers[1]} = {result}"
105
  elif "times" in msg or "*" in msg or "x" in msg:
106
  result = int(numbers[0]) * int(numbers[1])
107
+ response = f"πŸ”’ {numbers[0]} Γ— {numbers[1]} = {result}"
108
  elif "divided" in msg or "/" in msg:
109
  if int(numbers[1]) != 0:
110
  result = int(numbers[0]) / int(numbers[1])
111
+ response = f"πŸ”’ {numbers[0]} Γ· {numbers[1]} = {result}"
112
  else:
113
+ response = "❌ Cannot divide by zero!"
114
+ else:
115
+ response = "Try: 'calculate 5 + 3' or '10 divided by 2'"
116
+ history.append((message, response))
117
+ return "", history
118
  except:
119
  pass
120
 
121
  # Greetings
122
  if any(word in msg for word in ["hello", "hi", "hey", "greetings"]):
123
+ greetings = [
124
  "Hello! How can I assist you today? πŸŽ™οΈ",
125
  "Hi there! Ready to help! πŸ’«",
126
+ "Greetings! What can I do for you? ✨",
127
+ "Hey! Jarvis at your service! πŸš€"
128
+ ]
129
+ response = random.choice(greetings)
130
+ history.append((message, response))
131
+ return "", history
132
 
133
  # Farewell
134
  if any(word in msg for word in ["bye", "goodbye", "see you"]):
135
+ farewells = [
136
  "Goodbye! I'm always here when you need me. πŸ‘‹",
137
  "See you later! Have a great day! 🌟",
138
  "Take care! Come back anytime! πŸ’™"
139
+ ]
140
+ response = random.choice(farewells)
141
+ history.append((message, response))
142
+ return "", history
143
 
144
+ # About Jarvis
145
  if any(word in msg for word in ["who are you", "your name"]):
146
+ response = "I'm Jarvis, your personal AI assistant! I can help with time, date, jokes, math, reminders, and more! πŸ€–"
147
+ history.append((message, response))
148
+ return "", history
149
 
150
  # How are you
151
  if "how are you" in msg:
152
+ response = "I'm doing great! Thanks for asking! How can I help you today? 😊"
153
+ history.append((message, response))
154
+ return "", history
155
 
156
  # Thanks
157
  if any(word in msg for word in ["thank", "thanks"]):
158
+ response = "You're welcome! Always happy to help! 😊"
159
+ history.append((message, response))
160
+ return "", history
161
 
162
  # Help
163
  if msg == "help" or msg == "what can you do":
164
+ response = """🎯 **Jarvis Commands**
 
 
 
 
 
 
165
 
166
  ⏰ **Time & Date**
167
  β€’ "What time is it?"
 
189
  β€’ "Thanks"
190
  β€’ "Goodbye"
191
 
 
 
 
192
  **Just type naturally!** πŸš€"""
193
+ history.append((message, response))
194
+ return "", history
195
+
196
+ # Default response
197
+ response = f"I heard: '{message}'. Try saying 'help' to see what I can do! 🎯"
198
+ history.append((message, response))
199
+ return "", history
200
 
201
  # Create Jarvis instance
202
  jarvis = Jarvis()
203
 
204
+ # Create Gradio interface
205
  with gr.Blocks(title="Jarvis AI Assistant", theme=gr.themes.Soft()) as demo:
206
+
207
  gr.Markdown("""
208
  # πŸŽ™οΈ **Jarvis AI - Your Personal Assistant**
209
 
210
+ ### *Smart, Fast, and Private - No Cloud Required*
211
 
212
  ---
213
  """)
214
 
215
+ chatbot = gr.Chatbot(
216
+ height=500,
217
+ bubble_full_width=False,
218
+ avatar_images=(None, "πŸ€–"),
219
+ label="Conversation"
220
+ )
221
 
222
  with gr.Row():
223
  msg = gr.Textbox(
 
229
  send = gr.Button("Send", variant="primary", scale=1)
230
 
231
  with gr.Row():
232
+ clear = gr.Button("Clear Chat", variant="secondary", size="sm")
233
 
234
  gr.Markdown("---")
235
  gr.Markdown("### πŸš€ **Quick Commands**")
236
 
237
+ # Quick command buttons
238
  quick_commands = [
239
  "Hello", "What time is it?", "Tell me a joke",
240
  "Calculate 25 * 4", "Remind me to buy milk", "Help"
241
  ]
242
 
243
+ # Create rows of buttons
244
  for i in range(0, len(quick_commands), 3):
245
  with gr.Row():
246
  for cmd in quick_commands[i:i+3]:
 
251
  ---
252
  ### ✨ **Features**
253
 
254
+ | Category | Examples |
255
+ |----------|----------|
256
  | πŸ• Time | "What time is it?" |
257
+ | πŸ“… Date | "What's today's date?" |
258
  | πŸ˜„ Jokes | "Tell me a joke" |
259
  | πŸ’ͺ Motivation | "Give me a quote" |
260
  | πŸ”’ Math | "Calculate 5 + 3" |
 
263
 
264
  ### πŸ”’ **Privacy Guarantee**
265
  - βœ… 100% local processing
266
+ - βœ… No data stored permanently
267
  - βœ… No external APIs
268
  - βœ… Your conversations stay private
269
 
270
+ ### πŸ’‘ **Pro Tips**
271
+ - Try different phrasings - I understand natural language!
272
+ - Use "Help" anytime to see all commands
273
+ - Reminders stay until you clear them or the session ends
274
+
275
  **Start by typing "Hello"!** πŸš€
276
  """)
277
 
278
+ # Connect the respond function
279
+ def respond(message, history):
280
+ return jarvis.respond(message, history)
 
 
 
 
 
 
 
 
 
281
 
282
  send.click(respond, [msg, chatbot], [msg, chatbot])
283
  msg.submit(respond, [msg, chatbot], [msg, chatbot])
 
285
 
286
  if __name__ == "__main__":
287
  print("=" * 60)
288
+ print("πŸš€ Jarvis AI Assistant is running!")
289
+ print("βœ… Status: Online")
290
+ print("βœ… Features: Time, Date, Jokes, Quotes, Math, Reminders, Chat")
291
+ print("βœ… Interface: Gradio " + gr.__version__)
292
  print("=" * 60)
293
  demo.launch(share=False)