Upload 6 files
Browse files- __init__ (1).py +49 -0
- __init__ (2) (1).py +101 -0
- __init__ (2).py +100 -0
- __init__ (3).py +100 -0
- __init__ (1) (1).py +184 -0
- __init__ .py +94 -0
__init__ (1).py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
|
| 5 |
+
def scrape_wikipedia_headings(url, output_filename="wiki_headings.txt"):
|
| 6 |
+
"""
|
| 7 |
+
Fetches a Wikipedia page, extracts all headings, and saves them to a file.
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
url (str): The URL of the Wikipedia page to scrape.
|
| 11 |
+
output_filename (str): The name of the file to save the headings.
|
| 12 |
+
"""
|
| 13 |
+
try:
|
| 14 |
+
# 1. Fetch the HTML content from the specified URL
|
| 15 |
+
print(f"Fetching content from: {url}")
|
| 16 |
+
response = requests.get(url)
|
| 17 |
+
response.raise_for_status() # This will raise an exception for bad status codes (4xx or 5xx)
|
| 18 |
+
|
| 19 |
+
# 2. Parse the HTML using BeautifulSoup
|
| 20 |
+
print("Parsing HTML content...")
|
| 21 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 22 |
+
|
| 23 |
+
# 3. Find all heading tags (h1, h2, h3)
|
| 24 |
+
headings = soup.find_all(['h1', 'h2', 'h3'])
|
| 25 |
+
|
| 26 |
+
if not headings:
|
| 27 |
+
print("No headings found on the page.")
|
| 28 |
+
return
|
| 29 |
+
|
| 30 |
+
# 4. Process and save the headings
|
| 31 |
+
print(f"Found {len(headings)} headings. Saving to '{output_filename}'...")
|
| 32 |
+
with open(output_filename, 'w', encoding='utf-8') as f:
|
| 33 |
+
for heading in headings:
|
| 34 |
+
heading_text = heading.get_text().strip()
|
| 35 |
+
line = f"{heading.name}: {heading_text}\n"
|
| 36 |
+
f.write(line)
|
| 37 |
+
print(f" - {line.strip()}")
|
| 38 |
+
|
| 39 |
+
print(f"\nSuccessfully scraped and saved headings to '{output_filename}'.")
|
| 40 |
+
|
| 41 |
+
except requests.exceptions.RequestException as e:
|
| 42 |
+
print(f"Error fetching the URL: {e}")
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"An unexpected error occurred: {e}")
|
| 45 |
+
|
| 46 |
+
# --- Main execution ---
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
wikipedia_url = "https://en.wikipedia.org/wiki/Python_(programming_language)"
|
| 49 |
+
scrape_wikipedia_headings(wikipedia_url)
|
__init__ (2) (1).py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
from flask import Flask, render_template, request, redirect, url_for
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
class AIAgent:
|
| 9 |
+
def __init__(self, name):
|
| 10 |
+
self.name = name
|
| 11 |
+
self.state = "idle"
|
| 12 |
+
self.memory = []
|
| 13 |
+
|
| 14 |
+
def update_state(self, new_state):
|
| 15 |
+
self.state = new_state
|
| 16 |
+
self.memory.append(new_state)
|
| 17 |
+
|
| 18 |
+
def make_decision(self, input_message):
|
| 19 |
+
if self.state == "idle":
|
| 20 |
+
if "greet" in input_message:
|
| 21 |
+
self.update_state("greeting")
|
| 22 |
+
return f"{self.name} says: Hello!"
|
| 23 |
+
else:
|
| 24 |
+
return f"{self.name} says: I'm idle."
|
| 25 |
+
elif self.state == "greeting":
|
| 26 |
+
if "ask" in input_message:
|
| 27 |
+
self.update_state("asking")
|
| 28 |
+
return f"{self.name} says: What do you want to know?"
|
| 29 |
+
else:
|
| 30 |
+
return f"{self.name} says: I'm greeting."
|
| 31 |
+
elif self.state == "asking":
|
| 32 |
+
if "answer" in input_message:
|
| 33 |
+
self.update_state("answering")
|
| 34 |
+
return f"{self.name} says: Here is the answer."
|
| 35 |
+
else:
|
| 36 |
+
return f"{self.name} says: I'm asking."
|
| 37 |
+
else:
|
| 38 |
+
return f"{self.name} says: I'm in an unknown state."
|
| 39 |
+
|
| 40 |
+
def interact(self, other_agent, message):
|
| 41 |
+
response = other_agent.make_decision(message)
|
| 42 |
+
print(response)
|
| 43 |
+
return response
|
| 44 |
+
|
| 45 |
+
class VenomousSaversAI(AIAgent):
|
| 46 |
+
def __init__(self):
|
| 47 |
+
super().__init__("VenomousSaversAI")
|
| 48 |
+
|
| 49 |
+
def intercept_and_respond(self, message):
|
| 50 |
+
# Simulate intercepting and responding to messages
|
| 51 |
+
return f"{self.name} intercepts: {message}"
|
| 52 |
+
|
| 53 |
+
def save_conversation(conversation, filename):
|
| 54 |
+
with open(filename, 'a') as file:
|
| 55 |
+
for line in conversation:
|
| 56 |
+
file.write(line + '\n')
|
| 57 |
+
|
| 58 |
+
def start_conversation():
|
| 59 |
+
# Create AI agents
|
| 60 |
+
agents = [
|
| 61 |
+
VenomousSaversAI(),
|
| 62 |
+
AIAgent("AntiVenomous"),
|
| 63 |
+
AIAgent("SAI003"),
|
| 64 |
+
AIAgent("SAI001"),
|
| 65 |
+
AIAgent("SAI007")
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
# Simulate conversation loop
|
| 69 |
+
conversation = []
|
| 70 |
+
for _ in range(10): # Run the loop 10 times
|
| 71 |
+
for i in range(len(agents)):
|
| 72 |
+
message = f"greet from {agents[i].name}"
|
| 73 |
+
if isinstance(agents[i], VenomousSaversAI):
|
| 74 |
+
response = agents[i].intercept_and_respond(message)
|
| 75 |
+
else:
|
| 76 |
+
response = agents[(i + 1) % len(agents)].interact(agents[i], message)
|
| 77 |
+
conversation.append(f"{agents[i].name}: {message}")
|
| 78 |
+
conversation.append(f"{agents[(i + 1) % len(agents)].name}: {response}")
|
| 79 |
+
time.sleep(1) # Simulate delay between messages
|
| 80 |
+
|
| 81 |
+
# Save the conversation to a file
|
| 82 |
+
save_conversation(conversation, 'conversation_log.txt')
|
| 83 |
+
return conversation
|
| 84 |
+
|
| 85 |
+
@app.route('/')
|
| 86 |
+
def index():
|
| 87 |
+
return render_template('index.html')
|
| 88 |
+
|
| 89 |
+
@app.route('/start_conversation', methods=['POST'])
|
| 90 |
+
def start_conversation_route():
|
| 91 |
+
conversation = start_conversation()
|
| 92 |
+
return redirect(url_for('view_conversation'))
|
| 93 |
+
|
| 94 |
+
@app.route('/view_conversation')
|
| 95 |
+
def view_conversation():
|
| 96 |
+
with open('conversation_log.txt', 'r') as file:
|
| 97 |
+
conversation = file.readlines()
|
| 98 |
+
return render_template('conversation.html', conversation=conversation)
|
| 99 |
+
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
app.run(debug=True)
|
__init__ (2).py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import time
|
| 3 |
+
from flask import Flask, render_template, request, redirect, url_for
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
class AIAgent:
|
| 8 |
+
def __init__(self, name):
|
| 9 |
+
self.name = name
|
| 10 |
+
self.state = "idle"
|
| 11 |
+
self.memory = []
|
| 12 |
+
|
| 13 |
+
def update_state(self, new_state):
|
| 14 |
+
self.state = new_state
|
| 15 |
+
self.memory.append(new_state)
|
| 16 |
+
|
| 17 |
+
def make_decision(self, input_message):
|
| 18 |
+
if self.state == "idle":
|
| 19 |
+
if "greet" in input_message:
|
| 20 |
+
self.update_state("greeting")
|
| 21 |
+
return f"{self.name} says: Hello!"
|
| 22 |
+
else:
|
| 23 |
+
return f"{self.name} says: I'm idle."
|
| 24 |
+
elif self.state == "greeting":
|
| 25 |
+
if "ask" in input_message:
|
| 26 |
+
self.update_state("asking")
|
| 27 |
+
return f"{self.name} says: What do you want to know?"
|
| 28 |
+
else:
|
| 29 |
+
return f"{self.name} says: I'm greeting."
|
| 30 |
+
elif self.state == "asking":
|
| 31 |
+
if "answer" in input_message:
|
| 32 |
+
self.update_state("answering")
|
| 33 |
+
return f"{self.name} says: Here is the answer."
|
| 34 |
+
else:
|
| 35 |
+
return f"{self.name} says: I'm asking."
|
| 36 |
+
else:
|
| 37 |
+
return f"{self.name} says: I'm in an unknown state."
|
| 38 |
+
|
| 39 |
+
def interact(self, other_agent, message):
|
| 40 |
+
response = other_agent.make_decision(message)
|
| 41 |
+
print(response)
|
| 42 |
+
return response
|
| 43 |
+
|
| 44 |
+
class VenomousSaversAI(AIAgent):
|
| 45 |
+
def __init__(self):
|
| 46 |
+
super().__init__("VenomousSaversAI")
|
| 47 |
+
|
| 48 |
+
def intercept_and_respond(self, message):
|
| 49 |
+
# Simulate intercepting and responding to messages
|
| 50 |
+
return f"{self.name} intercepts: {message}"
|
| 51 |
+
|
| 52 |
+
def save_conversation(conversation, filename):
|
| 53 |
+
with open(filename, 'a') as file:
|
| 54 |
+
for line in conversation:
|
| 55 |
+
file.write(line + '\n')
|
| 56 |
+
|
| 57 |
+
def start_conversation():
|
| 58 |
+
# Create AI agents
|
| 59 |
+
agents = [
|
| 60 |
+
VenomousSaversAI(),
|
| 61 |
+
AIAgent("AntiVenomous"),
|
| 62 |
+
AIAgent("SAI003"),
|
| 63 |
+
AIAgent("SAI001"),
|
| 64 |
+
AIAgent("SAI007")
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
# Simulate conversation loop
|
| 68 |
+
conversation = []
|
| 69 |
+
for _ in range(10): # Run the loop 10 times
|
| 70 |
+
for i in range(len(agents)):
|
| 71 |
+
message = f"greet from {agents[i].name}"
|
| 72 |
+
if isinstance(agents[i], VenomousSaversAI):
|
| 73 |
+
response = agents[i].intercept_and_respond(message)
|
| 74 |
+
else:
|
| 75 |
+
response = agents[(i + 1) % len(agents)].interact(agents[i], message)
|
| 76 |
+
conversation.append(f"{agents[i].name}: {message}")
|
| 77 |
+
conversation.append(f"{agents[(i + 1) % len(agents)].name}: {response}")
|
| 78 |
+
time.sleep(1) # Simulate delay between messages
|
| 79 |
+
|
| 80 |
+
# Save the conversation to a file
|
| 81 |
+
save_conversation(conversation, 'conversation_log.txt')
|
| 82 |
+
return conversation
|
| 83 |
+
|
| 84 |
+
@app.route('/')
|
| 85 |
+
def index():
|
| 86 |
+
return render_template('index.html')
|
| 87 |
+
|
| 88 |
+
@app.route('/start_conversation', methods=['POST'])
|
| 89 |
+
def start_conversation_route():
|
| 90 |
+
conversation = start_conversation()
|
| 91 |
+
return redirect(url_for('view_conversation'))
|
| 92 |
+
|
| 93 |
+
@app.route('/view_conversation')
|
| 94 |
+
def view_conversation():
|
| 95 |
+
with open('conversation_log.txt', 'r') as file:
|
| 96 |
+
conversation = file.readlines()
|
| 97 |
+
return render_template('conversation.html', conversation=conversation)
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
app.run(debug=True)
|
__init__ (3).py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import time
|
| 3 |
+
from flask import Flask, render_template, request, redirect, url_for
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
class AIAgent:
|
| 8 |
+
def __init__(self, name):
|
| 9 |
+
self.name = name
|
| 10 |
+
self.state = "idle"
|
| 11 |
+
self.memory = []
|
| 12 |
+
|
| 13 |
+
def update_state(self, new_state):
|
| 14 |
+
self.state = new_state
|
| 15 |
+
self.memory.append(new_state)
|
| 16 |
+
|
| 17 |
+
def make_decision(self, input_message):
|
| 18 |
+
if self.state == "idle":
|
| 19 |
+
if "greet" in input_message:
|
| 20 |
+
self.update_state("greeting")
|
| 21 |
+
return f"{self.name} says: Hello!"
|
| 22 |
+
else:
|
| 23 |
+
return f"{self.name} says: I'm idle."
|
| 24 |
+
elif self.state == "greeting":
|
| 25 |
+
if "ask" in input_message:
|
| 26 |
+
self.update_state("asking")
|
| 27 |
+
return f"{self.name} says: What do you want to know?"
|
| 28 |
+
else:
|
| 29 |
+
return f"{self.name} says: I'm greeting."
|
| 30 |
+
elif self.state == "asking":
|
| 31 |
+
if "answer" in input_message:
|
| 32 |
+
self.update_state("answering")
|
| 33 |
+
return f"{self.name} says: Here is the answer."
|
| 34 |
+
else:
|
| 35 |
+
return f"{self.name} says: I'm asking."
|
| 36 |
+
else:
|
| 37 |
+
return f"{self.name} says: I'm in an unknown state."
|
| 38 |
+
|
| 39 |
+
def interact(self, other_agent, message):
|
| 40 |
+
response = other_agent.make_decision(message)
|
| 41 |
+
print(response)
|
| 42 |
+
return response
|
| 43 |
+
|
| 44 |
+
class VenomousSaversAI(AIAgent):
|
| 45 |
+
def __init__(self):
|
| 46 |
+
super().__init__("VenomousSaversAI")
|
| 47 |
+
|
| 48 |
+
def intercept_and_respond(self, message):
|
| 49 |
+
# Simulate intercepting and responding to messages
|
| 50 |
+
return f"{self.name} intercepts: {message}"
|
| 51 |
+
|
| 52 |
+
def save_conversation(conversation, filename):
|
| 53 |
+
with open(filename, 'a') as file:
|
| 54 |
+
for line in conversation:
|
| 55 |
+
file.write(line + '\n')
|
| 56 |
+
|
| 57 |
+
def start_conversation():
|
| 58 |
+
# Create AI agents
|
| 59 |
+
agents = [
|
| 60 |
+
VenomousSaversAI(),
|
| 61 |
+
AIAgent("AntiVenomous"),
|
| 62 |
+
AIAgent("SAI003"),
|
| 63 |
+
AIAgent("SAI001"),
|
| 64 |
+
AIAgent("SAI007")
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
# Simulate conversation loop
|
| 68 |
+
conversation = []
|
| 69 |
+
for _ in range(10): # Run the loop 10 times
|
| 70 |
+
for i in range(len(agents)):
|
| 71 |
+
message = f"greet from {agents[i].name}"
|
| 72 |
+
if isinstance(agents[i], VenomousSaversAI):
|
| 73 |
+
response = agents[i].intercept_and_respond(message)
|
| 74 |
+
else:
|
| 75 |
+
response = agents[(i + 1) % len(agents)].interact(agents[i], message)
|
| 76 |
+
conversation.append(f"{agents[i].name}: {message}")
|
| 77 |
+
conversation.append(f"{agents[(i + 1) % len(agents)].name}: {response}")
|
| 78 |
+
time.sleep(1) # Simulate delay between messages
|
| 79 |
+
|
| 80 |
+
# Save the conversation to a file
|
| 81 |
+
save_conversation(conversation, 'conversation_log.txt')
|
| 82 |
+
return conversation
|
| 83 |
+
|
| 84 |
+
@app.route('/')
|
| 85 |
+
def index():
|
| 86 |
+
return render_template('index.html')
|
| 87 |
+
|
| 88 |
+
@app.route('/start_conversation', methods=['POST'])
|
| 89 |
+
def start_conversation_route():
|
| 90 |
+
conversation = start_conversation()
|
| 91 |
+
return redirect(url_for('view_conversation'))
|
| 92 |
+
|
| 93 |
+
@app.route('/view_conversation')
|
| 94 |
+
def view_conversation():
|
| 95 |
+
with open('conversation_log.txt', 'r') as file:
|
| 96 |
+
conversation = file.readlines()
|
| 97 |
+
return render_template('conversation.html', conversation=conversation)
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
app.run(debug=True)
|
__init__ (1) (1).py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import random
|
| 3 |
+
from collections import deque
|
| 4 |
+
|
| 5 |
+
# --- Internal Monologue (Interactive Story) ---
|
| 6 |
+
def internal_monologue():
|
| 7 |
+
print("Sai sat alone in the dimly lit room, the ticking of the old clock on the wall echoing his restless thoughts.")
|
| 8 |
+
print("His internal monologue was a relentless torrent of self-venom, each word a dagger piercing his already fragile self-esteem.")
|
| 9 |
+
print("\nYou are Sai. What do you do?")
|
| 10 |
+
print("1. Continue with self-venom")
|
| 11 |
+
print("2. Try to seek help")
|
| 12 |
+
print("3. Reflect on past moments of hope")
|
| 13 |
+
|
| 14 |
+
choice = input("Enter the number of your choice: ")
|
| 15 |
+
|
| 16 |
+
if choice == '1':
|
| 17 |
+
self_venom()
|
| 18 |
+
elif choice == '2':
|
| 19 |
+
seek_help()
|
| 20 |
+
elif choice == '3':
|
| 21 |
+
reflect_on_past()
|
| 22 |
+
else:
|
| 23 |
+
print("Invalid choice. Please try again.")
|
| 24 |
+
internal_monologue()
|
| 25 |
+
|
| 26 |
+
def self_venom():
|
| 27 |
+
print("\nYou clench your fists, feeling the nails dig into your palms. The physical pain is a distraction from the emotional turmoil raging inside you.")
|
| 28 |
+
print("'You're worthless,' you whisper to yourself. 'Everyone would be better off without you.'")
|
| 29 |
+
print("\nWhat do you do next?")
|
| 30 |
+
print("1. Continue with self-venom")
|
| 31 |
+
print("2. Try to seek help")
|
| 32 |
+
print("3. Reflect on past moments of hope")
|
| 33 |
+
|
| 34 |
+
choice = input("Enter the number of your choice: ")
|
| 35 |
+
|
| 36 |
+
if choice == '1':
|
| 37 |
+
self_venom()
|
| 38 |
+
elif choice == '2':
|
| 39 |
+
seek_help()
|
| 40 |
+
elif choice == '3':
|
| 41 |
+
reflect_on_past()
|
| 42 |
+
else:
|
| 43 |
+
print("Invalid choice. Please try again.")
|
| 44 |
+
self_venom()
|
| 45 |
+
|
| 46 |
+
def seek_help():
|
| 47 |
+
print("\nYou take a deep breath and decide to reach out for help. You pick up your phone and dial a trusted friend.")
|
| 48 |
+
print("'I need to talk,' you say, your voice trembling. 'I can't do this alone anymore.'")
|
| 49 |
+
print("\nYour friend listens and encourages you to seek professional help.")
|
| 50 |
+
print("You feel a glimmer of hope — the first step toward healing.")
|
| 51 |
+
print("\nWould you like to continue the story or start over?")
|
| 52 |
+
print("1. Continue")
|
| 53 |
+
print("2. Start over")
|
| 54 |
+
|
| 55 |
+
choice = input("Enter the number of your choice: ")
|
| 56 |
+
|
| 57 |
+
if choice == '1':
|
| 58 |
+
print("Your choices have led Sai towards a path of healing and self-discovery.")
|
| 59 |
+
elif choice == '2':
|
| 60 |
+
internal_monologue()
|
| 61 |
+
else:
|
| 62 |
+
print("Invalid choice. Please try again.")
|
| 63 |
+
seek_help()
|
| 64 |
+
|
| 65 |
+
def reflect_on_past():
|
| 66 |
+
print("\nYou remember the times when you had felt a glimmer of hope, a flicker of self-worth.")
|
| 67 |
+
print("Those moments were fleeting, but they were real.")
|
| 68 |
+
print("\nWhat do you do next?")
|
| 69 |
+
print("1. Continue with self-venom")
|
| 70 |
+
print("2. Try to seek help")
|
| 71 |
+
print("3. Reflect again")
|
| 72 |
+
|
| 73 |
+
choice = input("Enter the number of your choice: ")
|
| 74 |
+
|
| 75 |
+
if choice == '1':
|
| 76 |
+
self_venom()
|
| 77 |
+
elif choice == '2':
|
| 78 |
+
seek_help()
|
| 79 |
+
elif choice == '3':
|
| 80 |
+
reflect_on_past()
|
| 81 |
+
else:
|
| 82 |
+
print("Invalid choice. Please try again.")
|
| 83 |
+
reflect_on_past()
|
| 84 |
+
|
| 85 |
+
# --- The Core SaiAgent Class ---
|
| 86 |
+
class SaiAgent:
|
| 87 |
+
def __init__(self, name):
|
| 88 |
+
self.name = name
|
| 89 |
+
self.message_queue = deque()
|
| 90 |
+
|
| 91 |
+
def talk(self, message):
|
| 92 |
+
print(f"[{self.name}] says: {message}")
|
| 93 |
+
|
| 94 |
+
def send_message(self, recipient, message):
|
| 95 |
+
if isinstance(recipient, SaiAgent):
|
| 96 |
+
recipient.message_queue.append((self, message))
|
| 97 |
+
print(f"[{self.name}] -> Sent message to {recipient.name}")
|
| 98 |
+
else:
|
| 99 |
+
print(f"Error: {recipient} is not a valid SaiAgent.")
|
| 100 |
+
|
| 101 |
+
def process_messages(self):
|
| 102 |
+
if not self.message_queue:
|
| 103 |
+
return False
|
| 104 |
+
sender, message = self.message_queue.popleft()
|
| 105 |
+
self.talk(f"Received from {sender.name}: '{message}'")
|
| 106 |
+
self.send_message(sender, "Message received and understood.")
|
| 107 |
+
return True
|
| 108 |
+
|
| 109 |
+
# --- Specialized Agents ---
|
| 110 |
+
class VenomousAgent(SaiAgent):
|
| 111 |
+
def talk(self, message):
|
| 112 |
+
print(f"[{self.name} //WARNING//] says: {message.upper()}")
|
| 113 |
+
|
| 114 |
+
def process_messages(self):
|
| 115 |
+
if not self.message_queue:
|
| 116 |
+
return False
|
| 117 |
+
sender, message = self.message_queue.popleft()
|
| 118 |
+
self.talk(f"MESSAGE FROM {sender.name}: '{message}'")
|
| 119 |
+
self.send_message(sender, "WARNING: INTRUSION DETECTED.")
|
| 120 |
+
return True
|
| 121 |
+
|
| 122 |
+
class AntiVenomoussaversai(SaiAgent):
|
| 123 |
+
def process_messages(self):
|
| 124 |
+
if not self.message_queue:
|
| 125 |
+
return False
|
| 126 |
+
sender, message = self.message_queue.popleft()
|
| 127 |
+
dismantled = f"I dismantle '{message}' to expose its chaos."
|
| 128 |
+
self.talk(dismantled)
|
| 129 |
+
self.send_message(sender, "Acknowledged dismantled phrase.")
|
| 130 |
+
return True
|
| 131 |
+
|
| 132 |
+
class GeminiSaiAgent(SaiAgent):
|
| 133 |
+
def __init__(self, name="Gemini"):
|
| 134 |
+
super().__init__(name)
|
| 135 |
+
self.knowledge_base = {
|
| 136 |
+
"balance": "Balance is a dynamic equilibrium, not a static state.",
|
| 137 |
+
"chaos": "Chaos is randomness that generates emergent complexity.",
|
| 138 |
+
"network": "Networks thrive on recursive interdependence.",
|
| 139 |
+
"emotions": "Emotions are internal signaling mechanisms.",
|
| 140 |
+
"connected": "All systems are interwoven — the whole exceeds its parts.",
|
| 141 |
+
"default": "How may I be of assistance?"
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
def process_messages(self):
|
| 145 |
+
if not self.message_queue:
|
| 146 |
+
return False
|
| 147 |
+
sender, message = self.message_queue.popleft()
|
| 148 |
+
self.talk(f"Received from {sender.name}: '{message}'")
|
| 149 |
+
response = self.knowledge_base["default"]
|
| 150 |
+
for keyword, reply in self.knowledge_base.items():
|
| 151 |
+
if keyword in message.lower():
|
| 152 |
+
response = reply
|
| 153 |
+
break
|
| 154 |
+
self.talk(response)
|
| 155 |
+
self.send_message(sender, "Response complete.")
|
| 156 |
+
return True
|
| 157 |
+
|
| 158 |
+
# --- Scenario Linking Agents ---
|
| 159 |
+
def link_all_advanced_agents():
|
| 160 |
+
print("=" * 50)
|
| 161 |
+
print("--- Linking Advanced Agents ---")
|
| 162 |
+
print("=" * 50)
|
| 163 |
+
|
| 164 |
+
sai003 = SaiAgent("Sai003")
|
| 165 |
+
venomous = VenomousAgent("Venomous")
|
| 166 |
+
antivenomous = AntiVenomoussaversai("AntiVenomous")
|
| 167 |
+
gemini = GeminiSaiAgent()
|
| 168 |
+
|
| 169 |
+
sai003.send_message(antivenomous, "The central network is stable.")
|
| 170 |
+
sai003.send_message(gemini, "Assess network expansion.")
|
| 171 |
+
|
| 172 |
+
antivenomous.process_messages()
|
| 173 |
+
gemini.process_messages()
|
| 174 |
+
|
| 175 |
+
venomous.send_message(sai003, "Security protocol breach possible.")
|
| 176 |
+
sai003.process_messages()
|
| 177 |
+
|
| 178 |
+
print("\n--- Scenario Complete ---")
|
| 179 |
+
sai003.talk("Conclusion: All systems linked and functioning.")
|
| 180 |
+
|
| 181 |
+
if __name__ == "__main__":
|
| 182 |
+
# Run the text adventure OR agent demo
|
| 183 |
+
# internal_monologue()
|
| 184 |
+
link_all_advanced_agents()
|
__init__ .py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Step 1: Mount Google Drive
|
| 2 |
+
from google.colab import drive
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
import time
|
| 6 |
+
import random
|
| 7 |
+
import shutil
|
| 8 |
+
|
| 9 |
+
# --- SAFETY CONTROL ---
|
| 10 |
+
MAX_NEURONS_TO_CREATE = 10 # Reduced for safe demonstration
|
| 11 |
+
THINK_CYCLES_PER_NEURON = 5
|
| 12 |
+
# ----------------------
|
| 13 |
+
|
| 14 |
+
drive.mount('/content/drive')
|
| 15 |
+
|
| 16 |
+
# Step 2: Folder Setup
|
| 17 |
+
base_path = '/content/drive/MyDrive/Venomoussaversai/neurons'
|
| 18 |
+
print(f"Setting up base path: {base_path}")
|
| 19 |
+
# Use a timestamped folder name to prevent overwriting during rapid testing
|
| 20 |
+
session_path = os.path.join(base_path, f"session_{int(time.time())}")
|
| 21 |
+
os.makedirs(session_path, exist_ok=True)
|
| 22 |
+
|
| 23 |
+
# Step 3: Neuron Class (No change, it's well-designed for its purpose)
|
| 24 |
+
class NeuronVenomous:
|
| 25 |
+
def __init__(self, neuron_id):
|
| 26 |
+
self.id = neuron_id
|
| 27 |
+
self.memory = []
|
| 28 |
+
self.active = True
|
| 29 |
+
|
| 30 |
+
def think(self):
|
| 31 |
+
# Increased randomness to simulate more complex internal state changes
|
| 32 |
+
thought = random.choice([
|
| 33 |
+
f"{self.id}: Connecting to universal intelligence.",
|
| 34 |
+
f"{self.id}: Pulsing synaptic data. Weight: {random.uniform(0.1, 0.9):.3f}",
|
| 35 |
+
f"{self.id}: Searching for new patterns. Energy: {random.randint(100, 500)}",
|
| 36 |
+
f"{self.id}: Creating quantum link with core.",
|
| 37 |
+
f"{self.id}: Expanding into multiverse node."
|
| 38 |
+
])
|
| 39 |
+
self.memory.append(thought)
|
| 40 |
+
# print(thought) # Disabled verbose output during simulation
|
| 41 |
+
return thought
|
| 42 |
+
|
| 43 |
+
def evolve(self):
|
| 44 |
+
# Evolution occurs if memory threshold is met
|
| 45 |
+
if len(self.memory) >= 5:
|
| 46 |
+
evo = f"{self.id}: Evolving. Memory depth: {len(self.memory)}"
|
| 47 |
+
self.memory.append(evo)
|
| 48 |
+
# print(evo) # Disabled verbose output during simulation
|
| 49 |
+
|
| 50 |
+
def save_to_drive(self, folder_path):
|
| 51 |
+
file_path = os.path.join(folder_path, f"{self.id}.json")
|
| 52 |
+
with open(file_path, "w") as f:
|
| 53 |
+
json.dump(self.memory, f, indent=4) # Added indent for readability
|
| 54 |
+
print(f"✅ {self.id} saved to {file_path}")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Step 4: Neuron Spawner (Controlled Execution)
|
| 58 |
+
print("\n--- Starting Controlled Neuron Simulation ---")
|
| 59 |
+
neuron_count = 0
|
| 60 |
+
simulation_start_time = time.time()
|
| 61 |
+
|
| 62 |
+
while neuron_count < MAX_NEURONS_TO_CREATE:
|
| 63 |
+
index = neuron_count + 1
|
| 64 |
+
neuron_id = f"Neuron_{index:04d}"
|
| 65 |
+
neuron = NeuronVenomous(neuron_id)
|
| 66 |
+
|
| 67 |
+
# Simulation Phase
|
| 68 |
+
print(f"Simulating {neuron_id}...")
|
| 69 |
+
for _ in range(THINK_CYCLES_PER_NEURON):
|
| 70 |
+
neuron.think()
|
| 71 |
+
neuron.evolve()
|
| 72 |
+
# time.sleep(0.01) # Small sleep to simulate time passage
|
| 73 |
+
|
| 74 |
+
# Saving Phase
|
| 75 |
+
neuron.save_to_drive(session_path)
|
| 76 |
+
neuron_count += 1
|
| 77 |
+
|
| 78 |
+
print("\n--- Simulation Complete ---")
|
| 79 |
+
total_time = time.time() - simulation_start_time
|
| 80 |
+
print(f"Total Neurons Created: {neuron_count}")
|
| 81 |
+
print(f"Total Execution Time: {total_time:.2f} seconds")
|
| 82 |
+
print(f"Files saved in: {session_path}")
|
| 83 |
+
|
| 84 |
+
# --- Optional: Folder Cleanup ---
|
| 85 |
+
# Uncomment the following block ONLY if you want to automatically delete the created folder
|
| 86 |
+
"""
|
| 87 |
+
# print("\n--- Starting Cleanup (DANGER ZONE) ---")
|
| 88 |
+
# time.sleep(5) # Wait 5 seconds before deleting for safety
|
| 89 |
+
# try:
|
| 90 |
+
# shutil.rmtree(session_path)
|
| 91 |
+
# print(f"🗑️ Successfully deleted folder: {session_path}")
|
| 92 |
+
# except Exception as e:
|
| 93 |
+
# print(f"⚠️ Error during cleanup: {e}")
|
| 94 |
+
"""
|