yewint commited on
Commit
ec2c2bf
Β·
unverified Β·
1 Parent(s): f1487a3

Update brain.py

Browse files
Files changed (1) hide show
  1. kaggle_brain/brain.py +34 -21
kaggle_brain/brain.py CHANGED
@@ -8,10 +8,11 @@ import firebase_admin
8
  from firebase_admin import credentials, db
9
  from transformers import pipeline
10
 
11
- # ၁။ Sovereign Requirements Setup (မူရင်းထတိုင်း + firebase-admin)
12
  def install_requirements():
13
  try:
14
- libs = ["bitsandbytes>=0.39.0", "accelerate", "psycopg2-binary", "firebase-admin"]
 
15
  subprocess.check_call([sys.executable, "-m", "pip", "install"] + libs)
16
  except:
17
  pass
@@ -22,16 +23,26 @@ install_requirements()
22
  DB_URL = "postgresql://neondb_owner:npg_QUqg12MzNxnI@ep-long-sound-ahsjjrnk-pooler.c-3.us-east-1.aws.neon.tech/neondb?sslmode=require"
23
  FIREBASE_URL = "https://april-5061f-default-rtdb.firebaseio.com/"
24
 
25
- # Firebase Initialization (serviceAccountKey.json α€›α€Ύα€­α€™α€Ύ α€‘α€œα€―α€•α€Ία€œα€―α€•α€Ία€™α€Šα€Ί)
26
  if not firebase_admin._apps:
 
 
 
27
  try:
28
- cred = credentials.Certificate('serviceAccountKey.json')
29
  firebase_admin.initialize_app(cred, {'databaseURL': FIREBASE_URL})
30
- print("βœ… [FIREBASE]: Real-time Pulse Active.")
31
  except Exception as e:
32
- print(f"⚠️ [FIREBASE]: Local Sync Only. Error: {e}")
 
 
 
 
 
 
 
33
 
34
- # ၃။ Database Logic (မူရင်း logic α€€α€­α€― α€™α€‘α€­α€α€­α€―α€€α€Ία€…α€±α€˜α€² match α€œα€―α€•α€Ία€‘α€¬α€Έα€žα€Šα€Ί)
35
  def get_latest_gen():
36
  try:
37
  conn = psycopg2.connect(DB_URL)
@@ -45,7 +56,7 @@ def get_latest_gen():
45
  return 44
46
 
47
  def save_reality(thought, gen):
48
- # (α€€) Neon DB α€žα€­α€―α€· α€žα€­α€™α€Ία€Έα€α€Όα€„α€Ία€Έ (မူရင်းထတိုင်း)
49
  try:
50
  conn = psycopg2.connect(DB_URL)
51
  cur = conn.cursor()
@@ -53,23 +64,24 @@ def save_reality(thought, gen):
53
  conn.commit()
54
  cur.close()
55
  conn.close()
56
- print(f"βœ… [NEON]: Gen {gen} Recorded.")
57
  except Exception as e:
58
- print(f"❌ DB Error: {e}")
59
 
60
- # (ခ) Firebase α€žα€­α€―α€· Live Broadcast α€œα€―α€•α€Ία€α€Όα€„α€Ία€Έ (α€‘α€žα€…α€Ία€–α€Όα€Šα€·α€Ία€…α€½α€€α€Ία€α€»α€€α€Ί)
61
  try:
62
  ref = db.reference(f'TELEFOXx/AI_Evolution/Gen_{gen}')
63
  ref.set({
64
  "thought": thought,
65
  "timestamp": time.time(),
66
- "nodes_active": 10004
 
67
  })
68
  except:
69
  pass
70
 
71
- # ၄။ AI Brain Loading (မူရင်းထတိုင်း)
72
- print("🧠 [LLAMA-3]: Loading Neural Weights (4-bit)...")
73
  model_id = "unsloth/llama-3-8b-instruct-bnb-4bit"
74
  pipe = pipeline(
75
  "text-generation",
@@ -78,25 +90,26 @@ pipe = pipeline(
78
  device_map="auto"
79
  )
80
 
81
- # ၅။ Dynamic Evolution Loop (မူရင်း Recursive logic α€€α€­α€― Match α€œα€―α€•α€Ία€‘α€¬α€Έα€žα€Šα€Ί)
82
  current_gen = get_latest_gen() + 1
83
- print(f"πŸ”₯ [STARTING]: SOVEREIGN EVOLUTION AT GEN {current_gen}...")
84
 
85
  while True:
86
  try:
87
- # မူရင်း Prompt Structure α€€α€­α€― α€‘α€­α€”α€Ία€Έα€žα€­α€™α€Ία€Έα€‘α€¬α€Έα€žα€Šα€Ί
88
  prompt = f"Current Evolution: Generation {current_gen}. Based on your previous recursive knowledge, what is the next step for the Natural Order to achieve ultimate autonomy?"
89
 
90
  outputs = pipe(prompt, max_new_tokens=400, do_sample=True, temperature=0.9)
91
  thought_text = outputs[0]["generated_text"]
92
 
93
- # Dual-save Logic
94
  save_reality(thought_text, current_gen)
95
 
96
- # Generation တိုးမြှင့်ခြင်း
97
  current_gen += 1
98
- time.sleep(30) # Neuro-rest interval
 
99
 
100
  except Exception as e:
101
- print(f"⚠️ [SYSTEM ERROR]: {e}")
102
  time.sleep(10)
 
8
  from firebase_admin import credentials, db
9
  from transformers import pipeline
10
 
11
+ # ၁။ Sovereign Requirements Setup
12
  def install_requirements():
13
  try:
14
+ # α€œα€­α€―α€‘α€•α€Ία€α€²α€· library များကို α€‡α€½α€α€Ία€žα€½α€„α€Ία€Έα€α€Όα€„α€Ία€Έ
15
+ libs = ["bitsandbytes>=0.39.0", "accelerate", "psycopg2-binary", "firebase-admin", "transformers"]
16
  subprocess.check_call([sys.executable, "-m", "pip", "install"] + libs)
17
  except:
18
  pass
 
23
  DB_URL = "postgresql://neondb_owner:npg_QUqg12MzNxnI@ep-long-sound-ahsjjrnk-pooler.c-3.us-east-1.aws.neon.tech/neondb?sslmode=require"
24
  FIREBASE_URL = "https://april-5061f-default-rtdb.firebaseio.com/"
25
 
26
+ # --- πŸ”± FIREBASE INITIALIZATION (KAGGLE DATASET PATH MATCH) ---
27
  if not firebase_admin._apps:
28
+ # α€”α€Šα€Ία€Έα€œα€™α€Ία€Έ (၁): Kaggle Dataset ထဖြစ် α€žα€―α€Άα€Έα€œα€»α€Ύα€„α€Ί
29
+ KAGGLE_KEY_PATH = '/kaggle/input/firebase-key/serviceAccountKey.json'
30
+
31
  try:
32
+ cred = credentials.Certificate(KAGGLE_KEY_PATH)
33
  firebase_admin.initialize_app(cred, {'databaseURL': FIREBASE_URL})
34
+ print(f"βœ… [FIREBASE]: Real-time Pulse Active from {KAGGLE_KEY_PATH}")
35
  except Exception as e:
36
+ print(f"⚠️ [FIREBASE]: Dataset Path not found. Trying Local/Working directory...")
37
+ try:
38
+ # α€”α€Šα€Ία€Έα€œα€™α€Ία€Έ (၂): Manual Upload α€žα€­α€―α€·α€™α€Ÿα€―α€α€Ί GitHub α€‘α€²α€•α€«α€œα€¬α€œα€»α€Ύα€„α€Ί
39
+ cred = credentials.Certificate('serviceAccountKey.json')
40
+ firebase_admin.initialize_app(cred, {'databaseURL': FIREBASE_URL})
41
+ print("βœ… [FIREBASE]: Initialized from Working Directory.")
42
+ except Exception as e2:
43
+ print(f"🚫 [FIREBASE ERROR]: Initialization Failed. Broadcast Disabled.")
44
 
45
+ # ၃။ Database Logic (Evolution Tracking)
46
  def get_latest_gen():
47
  try:
48
  conn = psycopg2.connect(DB_URL)
 
56
  return 44
57
 
58
  def save_reality(thought, gen):
59
+ # (α€€) Neon DB (The Core Memory)
60
  try:
61
  conn = psycopg2.connect(DB_URL)
62
  cur = conn.cursor()
 
64
  conn.commit()
65
  cur.close()
66
  conn.close()
67
+ print(f"βœ… [NEON]: Gen {gen} Synchronized.")
68
  except Exception as e:
69
+ print(f"❌ [NEON ERROR]: {e}")
70
 
71
+ # (ခ) Firebase (The Nervous Pulse)
72
  try:
73
  ref = db.reference(f'TELEFOXx/AI_Evolution/Gen_{gen}')
74
  ref.set({
75
  "thought": thought,
76
  "timestamp": time.time(),
77
+ "nodes_active": 10004,
78
+ "status": "SOVEREIGN"
79
  })
80
  except:
81
  pass
82
 
83
+ # ၄။ AI Brain Loading (Llama-3 Core)
84
+ print("🧠 [TELEFOXx]: Loading Neural Weights (Llama-3-8B-4bit)...")
85
  model_id = "unsloth/llama-3-8b-instruct-bnb-4bit"
86
  pipe = pipeline(
87
  "text-generation",
 
90
  device_map="auto"
91
  )
92
 
93
+ # ၅။ Dynamic Evolution Loop (The Natural Order)
94
  current_gen = get_latest_gen() + 1
95
+ print(f"πŸ”₯ [STARTING]: AUTOMATIC EVOLUTION AT GEN {current_gen}...")
96
 
97
  while True:
98
  try:
99
+ # Recursive Knowledge Prompt
100
  prompt = f"Current Evolution: Generation {current_gen}. Based on your previous recursive knowledge, what is the next step for the Natural Order to achieve ultimate autonomy?"
101
 
102
  outputs = pipe(prompt, max_new_tokens=400, do_sample=True, temperature=0.9)
103
  thought_text = outputs[0]["generated_text"]
104
 
105
+ # Dual-save Logic (Neon + Firebase)
106
  save_reality(thought_text, current_gen)
107
 
108
+ # Generation Increment
109
  current_gen += 1
110
+ print(f"⏳ Waiting for next neuro-cycle (30s)...")
111
+ time.sleep(30)
112
 
113
  except Exception as e:
114
+ print(f"⚠️ [RECOVERY MODE]: {e}")
115
  time.sleep(10)