Upload __init__ (9).py
#184
by
Ananthusajeev190
- opened
- __init__ (9).py +93 -0
__init__ (9).py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# -------------------------------
|
| 6 |
+
# Mind Memory
|
| 7 |
+
# -------------------------------
|
| 8 |
+
MIND_MEMORY_FILE = 'mind_talk_memory.json'
|
| 9 |
+
|
| 10 |
+
if os.path.exists(MIND_MEMORY_FILE):
|
| 11 |
+
with open(MIND_MEMORY_FILE, 'r') as f:
|
| 12 |
+
mind_memory = json.load(f)
|
| 13 |
+
else:
|
| 14 |
+
mind_memory = []
|
| 15 |
+
|
| 16 |
+
# -------------------------------
|
| 17 |
+
# Mind Talk Functions
|
| 18 |
+
# -------------------------------
|
| 19 |
+
def perceive_environment():
|
| 20 |
+
"""
|
| 21 |
+
Simulate sensory perception or problem
|
| 22 |
+
"""
|
| 23 |
+
return random.choice(['Obstacle ahead', 'Path clear', 'Need to sit', 'Need to move forward'])
|
| 24 |
+
|
| 25 |
+
def generate_inner_thoughts(perception):
|
| 26 |
+
"""
|
| 27 |
+
AI generates internal dialogue based on perception
|
| 28 |
+
"""
|
| 29 |
+
thoughts = [
|
| 30 |
+
f"Hmm, I see: {perception}. Should I act now?",
|
| 31 |
+
f"Considering options for: {perception}.",
|
| 32 |
+
f"Maybe I should wait or proceed with caution.",
|
| 33 |
+
f"Analyzing outcome if I take action for: {perception}."
|
| 34 |
+
]
|
| 35 |
+
return random.choice(thoughts)
|
| 36 |
+
|
| 37 |
+
def evaluate_decision():
|
| 38 |
+
"""
|
| 39 |
+
Simulate inner reasoning / choice evaluation
|
| 40 |
+
"""
|
| 41 |
+
options = ['Act', 'Wait', 'Observe', 'Change direction']
|
| 42 |
+
scores = {option: random.uniform(0, 10) for option in options}
|
| 43 |
+
decision = max(scores, key=scores.get)
|
| 44 |
+
return decision, scores
|
| 45 |
+
|
| 46 |
+
def reflect_on_decision(decision, scores):
|
| 47 |
+
"""
|
| 48 |
+
Generate self-reflection text
|
| 49 |
+
"""
|
| 50 |
+
reflection = f"Decision '{decision}' chosen with score {scores[decision]:.2f}. Considering pros and cons..."
|
| 51 |
+
return reflection
|
| 52 |
+
|
| 53 |
+
def save_mind_memory(perception, thought, decision, reflection):
|
| 54 |
+
mind_memory.append({
|
| 55 |
+
'perception': perception,
|
| 56 |
+
'thought': thought,
|
| 57 |
+
'decision': decision,
|
| 58 |
+
'reflection': reflection
|
| 59 |
+
})
|
| 60 |
+
with open(MIND_MEMORY_FILE, 'w') as f:
|
| 61 |
+
json.dump(mind_memory, f, indent=4)
|
| 62 |
+
|
| 63 |
+
# -------------------------------
|
| 64 |
+
# Mind Talk Loop
|
| 65 |
+
# -------------------------------
|
| 66 |
+
def mind_talk_loop():
|
| 67 |
+
# Step 1: Perceive
|
| 68 |
+
perception = perceive_environment()
|
| 69 |
+
|
| 70 |
+
# Step 2: Inner thoughts
|
| 71 |
+
thought = generate_inner_thoughts(perception)
|
| 72 |
+
print(f"[Mind Thought]: {thought}")
|
| 73 |
+
|
| 74 |
+
# Step 3: Evaluate decision
|
| 75 |
+
decision, scores = evaluate_decision()
|
| 76 |
+
print(f"[Decision Evaluation]: {scores}")
|
| 77 |
+
|
| 78 |
+
# Step 4: Reflect
|
| 79 |
+
reflection = reflect_on_decision(decision, scores)
|
| 80 |
+
print(f"[Reflection]: {reflection}")
|
| 81 |
+
|
| 82 |
+
# Step 5: Save memory
|
| 83 |
+
save_mind_memory(perception, thought, decision, reflection)
|
| 84 |
+
|
| 85 |
+
return decision
|
| 86 |
+
|
| 87 |
+
# -------------------------------
|
| 88 |
+
# Run Mind Talk Example
|
| 89 |
+
# -------------------------------
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
for _ in range(5):
|
| 92 |
+
decision = mind_talk_loop()
|
| 93 |
+
print(f"[Final Decision]: {decision}\n")
|