Maheen001 commited on
Commit
135bd9e
Β·
verified Β·
1 Parent(s): e4f07ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -230
app.py CHANGED
@@ -1,10 +1,6 @@
1
  """
2
  LifeAdmin AI - Main Gradio Application
3
  Hackathon Project: Track 2 - MCP in Action
4
- Hugging Face MCP Birthday Hackathon
5
-
6
- An autonomous life management agent with real MCP tool servers,
7
- RAG-enabled document search, and voice control.
8
  """
9
 
10
  import gradio as gr
@@ -26,19 +22,21 @@ Path("data/uploads").mkdir(parents=True, exist_ok=True)
26
  Path("data/outputs").mkdir(parents=True, exist_ok=True)
27
  Path("data/chroma_db").mkdir(parents=True, exist_ok=True)
28
 
29
- # Initialize agent
30
  print("πŸ€– Initializing LifeAdmin AI Agent...")
31
  agent = LifeAdminAgent()
32
  print("βœ“ Agent initialized successfully!")
33
 
34
- # Custom CSS for beautiful UI
 
 
35
  custom_css = """
 
 
36
  /* Main container styling */
37
  .gradio-container {
38
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
39
  max-width: 1400px !important;
40
  }
41
-
42
  /* Header styling */
43
  .header-container {
44
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
@@ -48,301 +46,120 @@ custom_css = """
48
  margin-bottom: 2rem;
49
  box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
50
  }
51
-
52
  .header-container h1 {
53
  margin: 0;
54
  font-size: 2.5rem;
55
  font-weight: 700;
56
- text-shadow: 0 2px 4px rgba(0,0,0,0.1);
57
  }
58
 
59
- .header-container p {
60
- margin: 0.5rem 0 0 0;
61
- opacity: 0.95;
62
- }
63
-
64
- /* Tool card styling */
65
  .tool-card {
66
  border: 2px solid #e2e8f0;
67
  border-radius: 0.75rem;
68
  padding: 1.25rem;
69
- transition: all 0.3s ease;
70
  background: white;
71
  margin: 0.5rem 0;
 
72
  }
73
-
74
  .tool-card:hover {
75
  border-color: #667eea;
76
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
77
  transform: translateY(-2px);
78
  }
79
 
80
- /* Thought bubble styling */
81
- .thought-bubble {
82
- background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
83
- border-left: 4px solid #667eea;
84
- padding: 1rem;
85
- margin: 0.75rem 0;
86
- border-radius: 0.5rem;
87
- box-shadow: 0 2px 4px rgba(0,0,0,0.05);
88
- }
89
-
90
- /* Success banner */
91
- .success-banner {
92
- background: linear-gradient(135deg, #c6f6d5 0%, #9ae6b4 100%);
93
- color: #22543d;
94
- padding: 1rem;
95
- border-radius: 0.5rem;
96
- border-left: 4px solid #38a169;
97
- font-weight: 500;
98
- }
99
-
100
- /* Error banner */
101
- .error-banner {
102
- background: linear-gradient(135deg, #fed7d7 0%, #fc8181 100%);
103
- color: #742a2a;
104
- padding: 1rem;
105
- border-radius: 0.5rem;
106
- border-left: 4px solid #e53e3e;
107
- font-weight: 500;
108
- }
109
-
110
- /* Button styling */
111
  .primary-button {
112
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
113
- border: none !important;
114
  color: white !important;
115
- font-weight: 600 !important;
116
- padding: 0.75rem 1.5rem !important;
117
- border-radius: 0.5rem !important;
118
- transition: all 0.3s ease !important;
119
  }
120
 
121
- .primary-button:hover {
122
- transform: translateY(-2px);
123
- box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4) !important;
124
- }
125
-
126
- /* Tab styling */
127
- .tab-nav button {
128
- font-weight: 500 !important;
129
- padding: 0.75rem 1.5rem !important;
130
- }
131
-
132
- .tab-nav button.selected {
133
- border-bottom: 3px solid #667eea !important;
134
- color: #667eea !important;
135
- }
136
-
137
- /* File upload area */
138
- .upload-area {
139
- border: 2px dashed #cbd5e0;
140
- border-radius: 0.75rem;
141
- padding: 2rem;
142
- text-align: center;
143
- transition: all 0.3s ease;
144
- }
145
-
146
- .upload-area:hover {
147
- border-color: #667eea;
148
- background: #f7fafc;
149
- }
150
-
151
- /* Status indicator */
152
- .status-indicator {
153
- display: inline-block;
154
- width: 10px;
155
- height: 10px;
156
- border-radius: 50%;
157
- margin-right: 0.5rem;
158
- animation: pulse 2s infinite;
159
- }
160
-
161
- @keyframes pulse {
162
- 0%, 100% { opacity: 1; }
163
- 50% { opacity: 0.5; }
164
- }
165
-
166
- .status-active {
167
- background: #48bb78;
168
- }
169
-
170
- .status-processing {
171
- background: #ed8936;
172
- }
173
-
174
- .status-error {
175
- background: #f56565;
176
- }
177
-
178
- /* Footer styling */
179
  .footer {
180
  text-align: center;
181
  margin-top: 3rem;
182
  padding: 1.5rem;
183
- border-top: 1px solid #e2e8f0;
184
  color: #718096;
185
  }
186
 
187
- /* Responsive adjustments */
188
- @media (max-width: 768px) {
189
- .header-container h1 {
190
- font-size: 1.75rem;
191
- }
192
-
193
- .gradio-container {
194
- padding: 1rem;
195
- }
196
- }
197
-
198
- /* Custom scrollbar */
199
- ::-webkit-scrollbar {
200
- width: 8px;
201
- }
202
-
203
- ::-webkit-scrollbar-track {
204
- background: #f1f1f1;
205
- }
206
-
207
- ::-webkit-scrollbar-thumb {
208
- background: #667eea;
209
- border-radius: 4px;
210
- }
211
-
212
- ::-webkit-scrollbar-thumb:hover {
213
- background: #764ba2;
214
- }
215
  """
216
 
 
 
 
217
  def create_app():
218
- """Create and configure the Gradio application"""
219
-
220
  app = gr.Blocks(
221
- css=custom_css,
222
  title="LifeAdmin AI - Your Autonomous Life Management Agent",
223
  analytics_enabled=False
224
  )
225
 
226
- # Apply theme AFTER creation
227
- app.theme = gr.themes.Soft(
228
- primary_hue="purple",
229
- secondary_hue="blue",
230
- neutral_hue="slate",
231
- font=[gr.themes.GoogleFont("Inter"), "system-ui", "sans-serif"],
232
- )
233
-
234
  with app:
 
 
235
 
236
- # Header
237
  with gr.Row():
238
  gr.HTML("""
239
  <div class="header-container">
240
  <h1>πŸ€– LifeAdmin AI</h1>
241
- <p style="font-size: 1.3rem; margin-top: 0.5rem;">
242
- Your Autonomous Life Management Agent
243
- </p>
244
- <p style="font-size: 0.95rem; margin-top: 0.75rem; opacity: 0.9;">
245
- Powered by 7 Real MCP Tool Servers β€’ Built for Hugging Face Hackathon
246
- </p>
247
- <div style="margin-top: 1rem; display: flex; gap: 1.5rem; font-size: 0.9rem;">
248
- <div style="display: flex; align-items: center; gap: 0.5rem;">
249
- <span>⚑</span>
250
- <span>Autonomous Execution</span>
251
- </div>
252
- <div style="display: flex; align-items: center; gap: 0.5rem;">
253
- <span>🎀</span>
254
- <span>Voice Control</span>
255
- </div>
256
- <div style="display: flex; align-items: center; gap: 0.5rem;">
257
- <span>πŸ”</span>
258
- <span>RAG-Powered Search</span>
259
- </div>
260
- <div style="display: flex; align-items: center; gap: 0.5rem;">
261
- <span>πŸ’Ύ</span>
262
- <span>Memory System</span>
263
- </div>
264
- </div>
265
  </div>
266
  """)
267
 
268
- with gr.Tabs() as tabs:
 
269
 
270
- with gr.Tab("πŸ“Š Manual Dashboard", id="manual"):
271
- gr.Markdown("""
272
- ### 🎯 Manual Mode
273
- Upload files and use individual tools with full control.
274
- """)
275
  create_manual_dashboard(agent)
276
 
277
- with gr.Tab("🎀 Voice Agent", id="voice"):
278
- gr.Markdown("""
279
- ### πŸ€– Voice Agent Mode
280
- Speak commands. Agent auto-plans and executes tasks.
281
- """)
282
  create_voice_agent_ui(agent)
283
 
284
- with gr.Tab("ℹ️ About", id="about"):
285
- gr.Markdown("### About LifeAdmin AI ...")
286
- # (your about text remains unchanged)
287
 
 
288
  gr.HTML("""
289
- <div class="footer">
290
- <p style="font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem;">
291
- πŸ† Hugging Face MCP Birthday Hackathon Submission
292
- </p>
293
- <p style="margin-bottom: 0.25rem;">
294
- Track 2: MCP in Action | Built with Gradio 6 & Real MCP Tool Servers
295
- </p>
296
- </div>
297
  """)
298
 
299
  return app
300
 
301
 
 
 
 
302
  if __name__ == "__main__":
303
  print("=" * 60)
304
  print("πŸš€ Starting LifeAdmin AI")
305
  print("=" * 60)
306
-
307
- # Setup LLM fallback chain
308
- print("\nβš™οΈ Setting up LLM providers...")
309
  try:
310
  setup_llm_fallback()
311
- print("βœ“ LLM providers configured successfully!")
312
  except Exception as e:
313
- print(f"⚠️ Warning: {e}")
314
- print(" Please set at least one API key (GROQ_API_KEY, OPENAI_API_KEY, etc.)")
315
-
316
- # Check for voice mode requirements
317
- print("\n🎀 Checking voice mode requirements...")
318
- if os.getenv('ELEVENLABS_API_KEY'):
319
- print("βœ“ ElevenLabs API key found (TTS enabled)")
320
- else:
321
- print("⚠️ ElevenLabs API key not found (voice output disabled)")
322
-
323
- if os.getenv('GROQ_API_KEY'):
324
- print("βœ“ Groq API key found (STT enabled)")
325
- else:
326
- print("⚠️ Groq API key not found (voice input disabled)")
327
-
328
- # Create and launch app
329
  print("\n🎨 Creating Gradio interface...")
330
  app = create_app()
331
-
332
  print("\nβœ… LifeAdmin AI is ready!")
333
- print("=" * 60)
334
- print("\nπŸ“± Access the app at: http://localhost:7860")
335
- print("\nπŸ’‘ Tips:")
336
- print(" - Use Manual Mode for precise control")
337
- print(" - Use Voice Mode for autonomous execution")
338
- print(" - Upload files to enable document-based commands")
339
- print("\n" + "=" * 60 + "\n")
340
-
341
- # Launch the application
342
  app.launch(
343
  server_name="0.0.0.0",
344
  server_port=int(os.getenv("GRADIO_SERVER_PORT", 7860)),
345
- share=False,
346
  show_error=True,
347
  show_api=False
348
- )
 
1
  """
2
  LifeAdmin AI - Main Gradio Application
3
  Hackathon Project: Track 2 - MCP in Action
 
 
 
 
4
  """
5
 
6
  import gradio as gr
 
22
  Path("data/outputs").mkdir(parents=True, exist_ok=True)
23
  Path("data/chroma_db").mkdir(parents=True, exist_ok=True)
24
 
 
25
  print("πŸ€– Initializing LifeAdmin AI Agent...")
26
  agent = LifeAdminAgent()
27
  print("βœ“ Agent initialized successfully!")
28
 
29
+ # -------------------------------------------
30
+ # CUSTOM CSS (Gradio 6: must be injected)
31
+ # -------------------------------------------
32
  custom_css = """
33
+ <style>
34
+
35
  /* Main container styling */
36
  .gradio-container {
37
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
38
  max-width: 1400px !important;
39
  }
 
40
  /* Header styling */
41
  .header-container {
42
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
 
46
  margin-bottom: 2rem;
47
  box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
48
  }
 
49
  .header-container h1 {
50
  margin: 0;
51
  font-size: 2.5rem;
52
  font-weight: 700;
 
53
  }
54
 
55
+ /* Tool card */
 
 
 
 
 
56
  .tool-card {
57
  border: 2px solid #e2e8f0;
58
  border-radius: 0.75rem;
59
  padding: 1.25rem;
 
60
  background: white;
61
  margin: 0.5rem 0;
62
+ transition: all .3s;
63
  }
 
64
  .tool-card:hover {
65
  border-color: #667eea;
66
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
67
  transform: translateY(-2px);
68
  }
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  .primary-button {
71
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
 
72
  color: white !important;
 
 
 
 
73
  }
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  .footer {
76
  text-align: center;
77
  margin-top: 3rem;
78
  padding: 1.5rem;
 
79
  color: #718096;
80
  }
81
 
82
+ </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  """
84
 
85
+ # ---------------------------------------------------------
86
+ # Create Gradio App (REMOVED: theme= , css= UNUSABLE NOW)
87
+ # ---------------------------------------------------------
88
  def create_app():
 
 
89
  app = gr.Blocks(
 
90
  title="LifeAdmin AI - Your Autonomous Life Management Agent",
91
  analytics_enabled=False
92
  )
93
 
 
 
 
 
 
 
 
 
94
  with app:
95
+ # Inject CSS into the top of the app
96
+ gr.HTML(custom_css)
97
 
98
+ # --- HEADER ---
99
  with gr.Row():
100
  gr.HTML("""
101
  <div class="header-container">
102
  <h1>πŸ€– LifeAdmin AI</h1>
103
+ <p>Your Autonomous Life Management Agent</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  </div>
105
  """)
106
 
107
+ # --- MAIN TABS ---
108
+ with gr.Tabs():
109
 
110
+ # Manual Dashboard
111
+ with gr.Tab("πŸ“Š Manual Dashboard"):
112
+ gr.Markdown("### 🎯 Manual Mode – Full Control Over Tools")
 
 
113
  create_manual_dashboard(agent)
114
 
115
+ # Voice Agent
116
+ with gr.Tab("🎀 Voice Agent"):
117
+ gr.Markdown("### πŸ€– Voice Agent – Speak Commands, Agent Executes")
 
 
118
  create_voice_agent_ui(agent)
119
 
120
+ # About
121
+ with gr.Tab("ℹ️ About"):
122
+ gr.Markdown("### About LifeAdmin AI\nComplete documentation here...")
123
 
124
+ # Footer
125
  gr.HTML("""
126
+ <div class="footer">
127
+ <p>πŸ† Hugging Face MCP Birthday Hackathon Submission</p>
128
+ <p>Track 2: MCP in Action | Built with Gradio 6</p>
129
+ </div>
 
 
 
 
130
  """)
131
 
132
  return app
133
 
134
 
135
+ # ---------------------------------------------------------
136
+ # MAIN ENTRY POINT
137
+ # ---------------------------------------------------------
138
  if __name__ == "__main__":
139
  print("=" * 60)
140
  print("πŸš€ Starting LifeAdmin AI")
141
  print("=" * 60)
142
+
143
+ print("\nβš™οΈ Setting up LLM providers...")
 
144
  try:
145
  setup_llm_fallback()
146
+ print("βœ“ LLM providers configured!")
147
  except Exception as e:
148
+ print(f"⚠️ Warning: {e}")
149
+
150
+ print("\n🎀 Checking voice requirements...")
151
+ print("βœ“ ElevenLabs API found" if os.getenv("ELEVENLABS_API_KEY") else "⚠️ Missing ElevenLabs API")
152
+ print("βœ“ Groq API found" if os.getenv("GROQ_API_KEY") else "⚠️ Missing Groq API")
153
+
 
 
 
 
 
 
 
 
 
 
154
  print("\n🎨 Creating Gradio interface...")
155
  app = create_app()
156
+
157
  print("\nβœ… LifeAdmin AI is ready!")
158
+ print("πŸ“± Open: http://localhost:7860")
159
+
 
 
 
 
 
 
 
160
  app.launch(
161
  server_name="0.0.0.0",
162
  server_port=int(os.getenv("GRADIO_SERVER_PORT", 7860)),
 
163
  show_error=True,
164
  show_api=False
165
+ )