Spaces:
Sleeping
Sleeping
Update brain.py
Browse files- 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
|
| 12 |
def install_requirements():
|
| 13 |
try:
|
| 14 |
-
|
|
|
|
| 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 |
-
#
|
| 26 |
if not firebase_admin._apps:
|
|
|
|
|
|
|
|
|
|
| 27 |
try:
|
| 28 |
-
cred = credentials.Certificate(
|
| 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]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
# αα Database Logic (
|
| 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}
|
| 57 |
except Exception as e:
|
| 58 |
-
print(f"β
|
| 59 |
|
| 60 |
-
# (α) Firebase
|
| 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("π§ [
|
| 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 (
|
| 82 |
current_gen = get_latest_gen() + 1
|
| 83 |
-
print(f"π₯ [STARTING]:
|
| 84 |
|
| 85 |
while True:
|
| 86 |
try:
|
| 87 |
-
#
|
| 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 |
-
|
|
|
|
| 99 |
|
| 100 |
except Exception as e:
|
| 101 |
-
print(f"β οΈ [
|
| 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)
|