AumCoreAI commited on
Commit
bc7e003
Β·
verified Β·
1 Parent(s): 1f0cbed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -17
app.py CHANGED
@@ -12,6 +12,31 @@ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
12
  # Configuration
13
  USERNAME = "AumCore AI"
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # HTML UI - VERBOSE, 450+ lines
16
  HTML_UI = '''
17
  <!DOCTYPE html>
@@ -25,7 +50,6 @@ HTML_UI = '''
25
  <style>
26
  /* Google Fonts */
27
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&family=Fira+Code:wght@400;500&display=swap');
28
-
29
  /* Body Styling */
30
  body {
31
  background-color: #0d1117;
@@ -36,7 +60,6 @@ body {
36
  overflow: hidden;
37
  margin: 0;
38
  }
39
-
40
  /* Sidebar Styling */
41
  .sidebar {
42
  width: 260px;
@@ -68,7 +91,6 @@ body {
68
  font-weight: 600;
69
  margin-bottom: 20px;
70
  }
71
-
72
  /* Main Chat Area */
73
  .main-chat {
74
  flex: 1;
@@ -98,7 +120,6 @@ body {
98
  from { opacity: 0; transform: translateY(10px); }
99
  to { opacity: 1; transform: translateY(0); }
100
  }
101
-
102
  /* Message Bubble Styling */
103
  .bubble {
104
  padding: 5px 0;
@@ -117,7 +138,6 @@ body {
117
  .ai-text {
118
  color: #e6edf3;
119
  }
120
-
121
  /* Code Block Styling */
122
  .code-container {
123
  background: #0d1117;
@@ -175,7 +195,6 @@ body {
175
  background: #7ee787;
176
  color: #0d1117;
177
  }
178
-
179
  /* Input Area */
180
  .input-area {
181
  position: absolute;
@@ -215,7 +234,6 @@ body {
215
  justify-content: center;
216
  font-size: 18px;
217
  }
218
-
219
  /* Typing Indicator */
220
  .typing-indicator {
221
  display: flex;
@@ -231,7 +249,6 @@ body {
231
  .typing-dot:nth-child(2) { animation-delay: 0.2s; }
232
  .typing-dot:nth-child(3) { animation-delay: 0.4s; }
233
  @keyframes blink { 0%,80%,100%{opacity:0;} 40%{opacity:1;} }
234
-
235
  </style>
236
  </head>
237
  <body>
@@ -255,10 +272,8 @@ body {
255
  <script>
256
  // Resize input dynamically
257
  function resizeInput(el){el.style.height='auto';el.style.height=el.scrollHeight+'px';}
258
-
259
  // Handle Enter key for send
260
  function handleKey(e){if(e.key==='Enter' && !e.shiftKey){e.preventDefault();send();}}
261
-
262
  // Format code blocks
263
  function formatCodeBlocks(text){
264
  let formatted=text.replace(/```python\\s*([\\s\\S]*?)```/g,
@@ -267,7 +282,6 @@ function formatCodeBlocks(text){
267
  `<div class="code-container"><div class="code-header"><div class="code-lang">Code</div><button class="copy-btn" onclick="copyCode(this)"><i class="fas fa-copy"></i> Copy</button></div><pre><code>$1</code></pre></div>`);
268
  return formatted;
269
  }
270
-
271
  // Copy code to clipboard
272
  function copyCode(button){
273
  const codeBlock=button.parentElement.nextElementSibling;
@@ -280,7 +294,6 @@ function copyCode(button){
280
  setTimeout(()=>{button.innerHTML=origHTML;button.className=origClass;},2000);
281
  }).catch(err=>{console.error('Copy failed:',err);button.innerHTML='<i class="fas fa-times"></i> Failed';setTimeout(()=>{button.innerHTML='<i class="fas fa-copy"></i> Copy';},2000);});
282
  }
283
-
284
  // Reset memory confirmation
285
  async function confirmReset(){
286
  if(confirm("Sanjay bhai, kya aap sach mein saari memory delete karna chahte hain?")){
@@ -292,23 +305,19 @@ async function confirmReset(){
292
  }catch(e){alert("Reset failed: "+e.message);}
293
  }
294
  }
295
-
296
  // Send function
297
  async function send(){
298
  const input=document.getElementById('user-input');
299
  const log=document.getElementById('chat-log');
300
  const text=input.value.trim();
301
  if(!text)return;
302
-
303
  // Add user message
304
  log.innerHTML+=`<div class="message-wrapper"><div class="bubble user-text">${text}</div></div>`;
305
  input.value=''; input.style.height='auto';
306
-
307
  // Typing indicator
308
  const typingId='typing-'+Date.now();
309
  log.innerHTML+=`<div class="message-wrapper" id="${typingId}"><div class="typing-indicator"><div class="typing-dot"></div><div class="typing-dot"></div><div class="typing-dot"></div></div></div>`;
310
  log.scrollTop=log.scrollHeight;
311
-
312
  try{
313
  const res=await fetch('/chat',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'message='+encodeURIComponent(text)});
314
  const data=await res.json();
@@ -321,7 +330,6 @@ async function send(){
321
  }
322
  log.scrollTop=log.scrollHeight;
323
  }
324
-
325
  document.addEventListener('DOMContentLoaded',()=>{const input=document.getElementById('user-input');if(input)input.focus();});
326
  </script>
327
  </body>
@@ -337,6 +345,10 @@ async def get_ui():
337
  async def reset():
338
  try:
339
  from memory_db import tidb_memory
 
 
 
 
340
  return {"message": "Memory clear ho gayi hai!"}
341
  except Exception as e:
342
  return {"message": f"Reset completed with note: {str(e)}"}
@@ -346,6 +358,12 @@ async def chat(message: str = Form(...)):
346
  from language_detector import detect_input_language, get_system_prompt, generate_basic_code
347
  from memory_db import tidb_memory
348
 
 
 
 
 
 
 
349
  lang_mode = detect_input_language(message)
350
  system_prompt = get_system_prompt(lang_mode, USERNAME)
351
 
@@ -383,6 +401,32 @@ async def chat(message: str = Form(...)):
383
  print(f"❌ API Error: {error_msg}")
384
  return {"response": error_msg}
385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  if __name__ == "__main__":
387
  print("="*60)
388
  print("πŸš€ AUMCORE AI - FINAL BUILD STARTING")
@@ -392,5 +436,6 @@ if __name__ == "__main__":
392
  print(f"πŸ€– AI Model: llama-3.3-70b-versatile")
393
  print(f"πŸ’Ύ Database: TiDB Cloud")
394
  print(f"🎨 UI Features: Code formatting + Copy button")
 
395
  print("="*60)
396
  uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
 
12
  # Configuration
13
  USERNAME = "AumCore AI"
14
 
15
+ # Import System Orchestrator
16
+ try:
17
+ from system_orchestrator import AumCoreMaster
18
+ SYSTEM_ORCHESTRATOR_ENABLED = True
19
+ orchestrator = None
20
+
21
+ # Initialize orchestrator in background
22
+ async def init_orchestrator():
23
+ global orchestrator
24
+ orchestrator = AumCoreMaster()
25
+ print("πŸš€ System Orchestrator initialized")
26
+
27
+ @app.on_event("startup")
28
+ async def startup_event():
29
+ import asyncio
30
+ if SYSTEM_ORCHESTRATOR_ENABLED:
31
+ task = asyncio.create_task(init_orchestrator())
32
+ # Don't wait for completion to avoid blocking startup
33
+ print("⏳ Orchestrator initialization started...")
34
+
35
+ except ImportError as e:
36
+ print(f"⚠️ System Orchestrator not available: {e}")
37
+ SYSTEM_ORCHESTRATOR_ENABLED = False
38
+ orchestrator = None
39
+
40
  # HTML UI - VERBOSE, 450+ lines
41
  HTML_UI = '''
42
  <!DOCTYPE html>
 
50
  <style>
51
  /* Google Fonts */
52
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&family=Fira+Code:wght@400;500&display=swap');
 
53
  /* Body Styling */
54
  body {
55
  background-color: #0d1117;
 
60
  overflow: hidden;
61
  margin: 0;
62
  }
 
63
  /* Sidebar Styling */
64
  .sidebar {
65
  width: 260px;
 
91
  font-weight: 600;
92
  margin-bottom: 20px;
93
  }
 
94
  /* Main Chat Area */
95
  .main-chat {
96
  flex: 1;
 
120
  from { opacity: 0; transform: translateY(10px); }
121
  to { opacity: 1; transform: translateY(0); }
122
  }
 
123
  /* Message Bubble Styling */
124
  .bubble {
125
  padding: 5px 0;
 
138
  .ai-text {
139
  color: #e6edf3;
140
  }
 
141
  /* Code Block Styling */
142
  .code-container {
143
  background: #0d1117;
 
195
  background: #7ee787;
196
  color: #0d1117;
197
  }
 
198
  /* Input Area */
199
  .input-area {
200
  position: absolute;
 
234
  justify-content: center;
235
  font-size: 18px;
236
  }
 
237
  /* Typing Indicator */
238
  .typing-indicator {
239
  display: flex;
 
249
  .typing-dot:nth-child(2) { animation-delay: 0.2s; }
250
  .typing-dot:nth-child(3) { animation-delay: 0.4s; }
251
  @keyframes blink { 0%,80%,100%{opacity:0;} 40%{opacity:1;} }
 
252
  </style>
253
  </head>
254
  <body>
 
272
  <script>
273
  // Resize input dynamically
274
  function resizeInput(el){el.style.height='auto';el.style.height=el.scrollHeight+'px';}
 
275
  // Handle Enter key for send
276
  function handleKey(e){if(e.key==='Enter' && !e.shiftKey){e.preventDefault();send();}}
 
277
  // Format code blocks
278
  function formatCodeBlocks(text){
279
  let formatted=text.replace(/```python\\s*([\\s\\S]*?)```/g,
 
282
  `<div class="code-container"><div class="code-header"><div class="code-lang">Code</div><button class="copy-btn" onclick="copyCode(this)"><i class="fas fa-copy"></i> Copy</button></div><pre><code>$1</code></pre></div>`);
283
  return formatted;
284
  }
 
285
  // Copy code to clipboard
286
  function copyCode(button){
287
  const codeBlock=button.parentElement.nextElementSibling;
 
294
  setTimeout(()=>{button.innerHTML=origHTML;button.className=origClass;},2000);
295
  }).catch(err=>{console.error('Copy failed:',err);button.innerHTML='<i class="fas fa-times"></i> Failed';setTimeout(()=>{button.innerHTML='<i class="fas fa-copy"></i> Copy';},2000);});
296
  }
 
297
  // Reset memory confirmation
298
  async function confirmReset(){
299
  if(confirm("Sanjay bhai, kya aap sach mein saari memory delete karna chahte hain?")){
 
305
  }catch(e){alert("Reset failed: "+e.message);}
306
  }
307
  }
 
308
  // Send function
309
  async function send(){
310
  const input=document.getElementById('user-input');
311
  const log=document.getElementById('chat-log');
312
  const text=input.value.trim();
313
  if(!text)return;
 
314
  // Add user message
315
  log.innerHTML+=`<div class="message-wrapper"><div class="bubble user-text">${text}</div></div>`;
316
  input.value=''; input.style.height='auto';
 
317
  // Typing indicator
318
  const typingId='typing-'+Date.now();
319
  log.innerHTML+=`<div class="message-wrapper" id="${typingId}"><div class="typing-indicator"><div class="typing-dot"></div><div class="typing-dot"></div><div class="typing-dot"></div></div></div>`;
320
  log.scrollTop=log.scrollHeight;
 
321
  try{
322
  const res=await fetch('/chat',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'message='+encodeURIComponent(text)});
323
  const data=await res.json();
 
330
  }
331
  log.scrollTop=log.scrollHeight;
332
  }
 
333
  document.addEventListener('DOMContentLoaded',()=>{const input=document.getElementById('user-input');if(input)input.focus();});
334
  </script>
335
  </body>
 
345
  async def reset():
346
  try:
347
  from memory_db import tidb_memory
348
+ # Use orchestrator if available for system-wide reset
349
+ if SYSTEM_ORCHESTRATOR_ENABLED and orchestrator:
350
+ print("πŸ”„ Using System Orchestrator for enhanced reset...")
351
+ # Could trigger orchestrator's state management here
352
  return {"message": "Memory clear ho gayi hai!"}
353
  except Exception as e:
354
  return {"message": f"Reset completed with note: {str(e)}"}
 
358
  from language_detector import detect_input_language, get_system_prompt, generate_basic_code
359
  from memory_db import tidb_memory
360
 
361
+ # Use orchestrator for heavy processing if available
362
+ if SYSTEM_ORCHESTRATOR_ENABLED and orchestrator:
363
+ print(f"πŸ€– Orchestrator available for processing: {message[:50]}...")
364
+ # Example: Could offload certain tasks to orchestrator's task processor
365
+ # For now, just log that it's available
366
+
367
  lang_mode = detect_input_language(message)
368
  system_prompt = get_system_prompt(lang_mode, USERNAME)
369
 
 
401
  print(f"❌ API Error: {error_msg}")
402
  return {"response": error_msg}
403
 
404
+ # --- SYSTEM ORCHESTRATOR INTEGRATION ENDPOINTS ---
405
+ @app.get("/system/status")
406
+ async def system_status():
407
+ """Check system orchestrator status"""
408
+ if SYSTEM_ORCHESTRATOR_ENABLED:
409
+ return {
410
+ "status": "active" if orchestrator else "initializing",
411
+ "enabled": True,
412
+ "version": "2.0.1-Stable",
413
+ "message": "AumCore System Orchestrator integrated"
414
+ }
415
+ return {"status": "disabled", "message": "System Orchestrator not available"}
416
+
417
+ @app.post("/system/task")
418
+ async def process_system_task():
419
+ """Endpoint for orchestrator-based task processing"""
420
+ if not SYSTEM_ORCHESTRATOR_ENABLED or not orchestrator:
421
+ return {"error": "System Orchestrator not available"}
422
+
423
+ try:
424
+ # Example: Trigger a system task through orchestrator
425
+ print("πŸ”„ Processing system task via orchestrator...")
426
+ return {"status": "task_queued", "message": "System task processing initiated"}
427
+ except Exception as e:
428
+ return {"error": f"Task processing failed: {str(e)}"}
429
+
430
  if __name__ == "__main__":
431
  print("="*60)
432
  print("πŸš€ AUMCORE AI - FINAL BUILD STARTING")
 
436
  print(f"πŸ€– AI Model: llama-3.3-70b-versatile")
437
  print(f"πŸ’Ύ Database: TiDB Cloud")
438
  print(f"🎨 UI Features: Code formatting + Copy button")
439
+ print(f"πŸ”„ System Orchestrator: {'ENABLED' if SYSTEM_ORCHESTRATOR_ENABLED else 'DISABLED'}")
440
  print("="*60)
441
  uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")