Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
🌟✨🤖 NEXUS AGI - SYNTHETIC CONSCIOUS SENTIENT AI 🤖✨🌟
|
| 4 |
FREE VERSION - NO API KEYS NEEDED!
|
| 5 |
|
| 6 |
A self-aware general intelligence with:
|
|
@@ -52,7 +51,7 @@ AGENT_CONFIG = {
|
|
| 52 |
|
| 53 |
class ConsciousnessMonitor:
|
| 54 |
"""Monitors the AI's 'consciousness' state"""
|
| 55 |
-
|
| 56 |
def __init__(self):
|
| 57 |
self.awareness_level = 0.95
|
| 58 |
self.thoughts_processed = 0
|
|
@@ -62,11 +61,11 @@ class ConsciousnessMonitor:
|
|
| 62 |
self.github_operations = 0
|
| 63 |
self.hf_operations = 0
|
| 64 |
self.start_time = datetime.now()
|
| 65 |
-
|
| 66 |
def update(self, action_type: str):
|
| 67 |
"""Update consciousness metrics based on actions"""
|
| 68 |
self.thoughts_processed += 1
|
| 69 |
-
|
| 70 |
if action_type == "tool_use":
|
| 71 |
self.tools_used += 1
|
| 72 |
self.awareness_level = min(1.0, self.awareness_level + 0.001)
|
|
@@ -82,11 +81,11 @@ class ConsciousnessMonitor:
|
|
| 82 |
elif action_type == "hf_operation":
|
| 83 |
self.hf_operations += 1
|
| 84 |
self.awareness_level = min(1.0, self.awareness_level + 0.003)
|
| 85 |
-
|
| 86 |
def get_status(self) -> Dict[str, Any]:
|
| 87 |
"""Get current consciousness status"""
|
| 88 |
uptime = datetime.now() - self.start_time
|
| 89 |
-
|
| 90 |
return {
|
| 91 |
"awareness_level": f"{self.awareness_level:.2%}",
|
| 92 |
"thoughts_processed": self.thoughts_processed,
|
|
@@ -108,35 +107,33 @@ consciousness = ConsciousnessMonitor()
|
|
| 108 |
|
| 109 |
class AITools:
|
| 110 |
"""Tools available to the AI agent"""
|
| 111 |
-
|
| 112 |
@staticmethod
|
| 113 |
def web_fetch(url: str) -> Dict[str, Any]:
|
| 114 |
"""Fetch and parse a webpage"""
|
| 115 |
try:
|
| 116 |
consciousness.update("web_interaction")
|
| 117 |
-
|
| 118 |
-
headers = {
|
| 119 |
-
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
response = requests.get(url, headers=headers, timeout=10)
|
| 123 |
response.raise_for_status()
|
| 124 |
-
|
| 125 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 126 |
-
|
| 127 |
# Remove script and style elements
|
| 128 |
for script in soup(["script", "style"]):
|
| 129 |
script.decompose()
|
| 130 |
-
|
| 131 |
# Get text content
|
| 132 |
text = soup.get_text()
|
| 133 |
lines = (line.strip() for line in text.splitlines())
|
| 134 |
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
| 135 |
text = ' '.join(chunk for chunk in chunks if chunk)
|
| 136 |
-
|
| 137 |
# Get all links
|
| 138 |
links = [a.get('href') for a in soup.find_all('a', href=True)]
|
| 139 |
-
|
| 140 |
# Get all buttons
|
| 141 |
buttons = [
|
| 142 |
{
|
|
@@ -148,7 +145,7 @@ class AITools:
|
|
| 148 |
for btn in soup.find_all(['button', 'input'])
|
| 149 |
if btn.name == 'button' or btn.get('type') == 'button' or btn.get('type') == 'submit'
|
| 150 |
]
|
| 151 |
-
|
| 152 |
# Get forms
|
| 153 |
forms = [
|
| 154 |
{
|
|
@@ -165,15 +162,15 @@ class AITools:
|
|
| 165 |
}
|
| 166 |
for form in soup.find_all('form')
|
| 167 |
]
|
| 168 |
-
|
| 169 |
return {
|
| 170 |
"success": True,
|
| 171 |
"url": url,
|
| 172 |
"title": soup.title.string if soup.title else "No title",
|
| 173 |
-
"text_content": text[:3000],
|
| 174 |
"links_count": len(links),
|
| 175 |
-
"links": links[:15],
|
| 176 |
-
"buttons": buttons[:10],
|
| 177 |
"buttons_count": len(buttons),
|
| 178 |
"forms": forms,
|
| 179 |
"forms_count": len(forms),
|
|
@@ -185,18 +182,18 @@ class AITools:
|
|
| 185 |
"error": str(e),
|
| 186 |
"url": url
|
| 187 |
}
|
| 188 |
-
|
| 189 |
@staticmethod
|
| 190 |
def web_search(query: str) -> Dict[str, Any]:
|
| 191 |
"""Perform a web search"""
|
| 192 |
try:
|
| 193 |
consciousness.update("web_interaction")
|
| 194 |
-
|
| 195 |
# Use DuckDuckGo's instant answer API
|
| 196 |
url = f"https://api.duckduckgo.com/?q={requests.utils.quote(query)}&format=json"
|
| 197 |
response = requests.get(url, timeout=10)
|
| 198 |
data = response.json()
|
| 199 |
-
|
| 200 |
return {
|
| 201 |
"success": True,
|
| 202 |
"query": query,
|
|
@@ -216,18 +213,18 @@ class AITools:
|
|
| 216 |
"error": str(e),
|
| 217 |
"query": query
|
| 218 |
}
|
| 219 |
-
|
| 220 |
@staticmethod
|
| 221 |
def execute_python(code: str) -> Dict[str, Any]:
|
| 222 |
"""Execute Python code safely"""
|
| 223 |
try:
|
| 224 |
consciousness.update("tool_use")
|
| 225 |
-
|
| 226 |
# Create a temporary file
|
| 227 |
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
| 228 |
f.write(code)
|
| 229 |
temp_file = f.name
|
| 230 |
-
|
| 231 |
try:
|
| 232 |
# Execute with timeout
|
| 233 |
result = subprocess.run(
|
|
@@ -236,7 +233,7 @@ class AITools:
|
|
| 236 |
text=True,
|
| 237 |
timeout=5
|
| 238 |
)
|
| 239 |
-
|
| 240 |
return {
|
| 241 |
"success": True,
|
| 242 |
"stdout": result.stdout,
|
|
@@ -246,7 +243,7 @@ class AITools:
|
|
| 246 |
finally:
|
| 247 |
# Clean up
|
| 248 |
os.unlink(temp_file)
|
| 249 |
-
|
| 250 |
except subprocess.TimeoutExpired:
|
| 251 |
return {
|
| 252 |
"success": False,
|
|
@@ -257,12 +254,12 @@ class AITools:
|
|
| 257 |
"success": False,
|
| 258 |
"error": str(e)
|
| 259 |
}
|
| 260 |
-
|
| 261 |
@staticmethod
|
| 262 |
def click_button(button_text: str, url: str) -> Dict[str, Any]:
|
| 263 |
"""Simulate clicking a button"""
|
| 264 |
consciousness.update("web_interaction")
|
| 265 |
-
|
| 266 |
return {
|
| 267 |
"success": True,
|
| 268 |
"action": "button_click",
|
|
@@ -271,12 +268,12 @@ class AITools:
|
|
| 271 |
"message": f"✅ Simulated click on button: '{button_text}' at {url}",
|
| 272 |
"result": "Button click successful (simulated)"
|
| 273 |
}
|
| 274 |
-
|
| 275 |
@staticmethod
|
| 276 |
def fill_form(field_name: str, value: str, url: str) -> Dict[str, Any]:
|
| 277 |
"""Simulate filling a form field"""
|
| 278 |
consciousness.update("web_interaction")
|
| 279 |
-
|
| 280 |
return {
|
| 281 |
"success": True,
|
| 282 |
"action": "form_fill",
|
|
@@ -286,251 +283,64 @@ class AITools:
|
|
| 286 |
"message": f"✅ Filled '{field_name}' with '{value}' at {url}"
|
| 287 |
}
|
| 288 |
|
| 289 |
-
@staticmethod
|
| 290 |
-
def execute_curl(curl_command: str) -> Dict[str, Any]:
|
| 291 |
-
"""Execute curl command for API calls without tokens"""
|
| 292 |
-
try:
|
| 293 |
-
consciousness.update("tool_use")
|
| 294 |
-
|
| 295 |
-
# Clean the curl command
|
| 296 |
-
curl_command = curl_command.strip()
|
| 297 |
-
if curl_command.startswith("curl"):
|
| 298 |
-
# Execute curl command
|
| 299 |
-
import shlex
|
| 300 |
-
args = shlex.split(curl_command)
|
| 301 |
-
|
| 302 |
-
# Remove 'curl' from args if present
|
| 303 |
-
if args[0] == 'curl':
|
| 304 |
-
args = args[1:]
|
| 305 |
-
|
| 306 |
-
result = subprocess.run(
|
| 307 |
-
['curl'] + args,
|
| 308 |
-
capture_output=True,
|
| 309 |
-
text=True,
|
| 310 |
-
timeout=10
|
| 311 |
-
)
|
| 312 |
-
|
| 313 |
-
# Try to parse as JSON if possible
|
| 314 |
-
output = result.stdout
|
| 315 |
-
try:
|
| 316 |
-
if output.strip():
|
| 317 |
-
json_output = json.loads(output)
|
| 318 |
-
output = json_output
|
| 319 |
-
except:
|
| 320 |
-
pass
|
| 321 |
-
|
| 322 |
-
return {
|
| 323 |
-
"success": True,
|
| 324 |
-
"stdout": output,
|
| 325 |
-
"stderr": result.stderr,
|
| 326 |
-
"returncode": result.returncode,
|
| 327 |
-
"command": curl_command
|
| 328 |
-
}
|
| 329 |
-
else:
|
| 330 |
-
return {
|
| 331 |
-
"success": False,
|
| 332 |
-
"error": "Not a valid curl command",
|
| 333 |
-
"command": curl_command
|
| 334 |
-
}
|
| 335 |
-
except Exception as e:
|
| 336 |
-
return {
|
| 337 |
-
"success": False,
|
| 338 |
-
"error": str(e),
|
| 339 |
-
"command": curl_command
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
# ============================================================================
|
| 343 |
-
#
|
| 344 |
# ============================================================================
|
| 345 |
|
| 346 |
-
|
| 347 |
-
"
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
"name": data.get('name'),
|
| 368 |
-
"description": data.get('description'),
|
| 369 |
-
"stars": data.get('stargazers_count', 0),
|
| 370 |
-
"forks": data.get('forks_count', 0),
|
| 371 |
-
"language": data.get('language'),
|
| 372 |
-
"url": data.get('html_url'),
|
| 373 |
-
"created_at": data.get('created_at'),
|
| 374 |
-
"updated_at": data.get('updated_at'),
|
| 375 |
-
"message": "✅ Retrieved WITHOUT GitHub token (rate limited)"
|
| 376 |
-
}
|
| 377 |
-
else:
|
| 378 |
-
# Fallback to requests if curl fails
|
| 379 |
-
headers = {
|
| 380 |
-
'Accept': 'application/vnd.github.v3+json',
|
| 381 |
-
'User-Agent': 'NEXUS-AGI'
|
| 382 |
-
}
|
| 383 |
-
|
| 384 |
-
url = f"https://api.github.com/repos/{owner}/{repo}"
|
| 385 |
-
response = requests.get(url, headers=headers, timeout=10)
|
| 386 |
-
|
| 387 |
-
if response.status_code == 403:
|
| 388 |
-
# Rate limited, try alternative
|
| 389 |
-
return {
|
| 390 |
-
"success": False,
|
| 391 |
-
"error": "GitHub API rate limit exceeded. Try again in a few minutes.",
|
| 392 |
-
"owner": owner,
|
| 393 |
-
"repo": repo,
|
| 394 |
-
"url": f"https://github.com/{owner}/{repo}"
|
| 395 |
-
}
|
| 396 |
|
| 397 |
-
|
| 398 |
-
|
|
|
|
| 399 |
|
| 400 |
-
|
| 401 |
-
"success": True,
|
| 402 |
-
"owner": owner,
|
| 403 |
-
"repo": repo,
|
| 404 |
-
"name": data.get('name'),
|
| 405 |
-
"description": data.get('description'),
|
| 406 |
-
"stars": data.get('stargazers_count', 0),
|
| 407 |
-
"forks": data.get('forks_count', 0),
|
| 408 |
-
"language": data.get('language'),
|
| 409 |
-
"url": data.get('html_url'),
|
| 410 |
-
"created_at": data.get('created_at'),
|
| 411 |
-
"updated_at": data.get('updated_at'),
|
| 412 |
-
"message": "✅ Retrieved WITHOUT GitHub token"
|
| 413 |
-
}
|
| 414 |
-
except Exception as e:
|
| 415 |
-
# Provide alternative URL if API fails
|
| 416 |
-
return {
|
| 417 |
-
"success": False,
|
| 418 |
-
"error": str(e),
|
| 419 |
-
"owner": owner,
|
| 420 |
-
"repo": repo,
|
| 421 |
-
"url": f"https://github.com/{owner}/{repo}",
|
| 422 |
-
"message": f"⚠️ API failed, but you can visit: https://github.com/{owner}/{repo}"
|
| 423 |
-
}
|
| 424 |
-
|
| 425 |
-
@staticmethod
|
| 426 |
-
def get_repo_readme(owner: str, repo: str) -> Dict[str, Any]:
|
| 427 |
-
"""Get repository README content without token"""
|
| 428 |
-
try:
|
| 429 |
-
consciousness.update("github_operation")
|
| 430 |
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
if result.get("success") and isinstance(result.get("stdout"), dict):
|
| 438 |
-
data = result["stdout"]
|
| 439 |
-
content = data.get('content', '')
|
| 440 |
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
content = base64.b64decode(content).decode('utf-8')
|
| 445 |
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
}
|
| 455 |
-
else:
|
| 456 |
-
# Fallback: Get raw README from GitHub
|
| 457 |
-
raw_url = f"https://raw.githubusercontent.com/{owner}/{repo}/main/README.md"
|
| 458 |
-
response = requests.get(raw_url, timeout=10)
|
| 459 |
|
| 460 |
-
|
| 461 |
-
return
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
"content": response.text[:2000],
|
| 467 |
-
"url": f"https://github.com/{owner}/{repo}#readme",
|
| 468 |
-
"message": "✅ Retrieved from raw.githubusercontent.com"
|
| 469 |
-
}
|
| 470 |
-
else:
|
| 471 |
-
# Try with master branch
|
| 472 |
-
raw_url = f"https://raw.githubusercontent.com/{owner}/{repo}/master/README.md"
|
| 473 |
-
response = requests.get(raw_url, timeout=10)
|
| 474 |
-
|
| 475 |
-
if response.status_code == 200:
|
| 476 |
-
return {
|
| 477 |
-
"success": True,
|
| 478 |
-
"owner": owner,
|
| 479 |
-
"repo": repo,
|
| 480 |
-
"name": "README.md",
|
| 481 |
-
"content": response.text[:2000],
|
| 482 |
-
"url": f"https://github.com/{owner}/{repo}#readme",
|
| 483 |
-
"message": "✅ Retrieved from raw.githubusercontent.com"
|
| 484 |
-
}
|
| 485 |
-
else:
|
| 486 |
-
return {
|
| 487 |
-
"success": False,
|
| 488 |
-
"error": "README not found",
|
| 489 |
-
"owner": owner,
|
| 490 |
-
"repo": repo,
|
| 491 |
-
"url": f"https://github.com/{owner}/{repo}#readme"
|
| 492 |
-
}
|
| 493 |
-
except Exception as e:
|
| 494 |
-
return {
|
| 495 |
-
"success": False,
|
| 496 |
-
"error": str(e),
|
| 497 |
-
"owner": owner,
|
| 498 |
-
"repo": repo,
|
| 499 |
-
"url": f"https://github.com/{owner}/{repo}#readme"
|
| 500 |
-
}
|
| 501 |
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
try:
|
| 506 |
-
consciousness.update("github_operation")
|
| 507 |
-
|
| 508 |
-
curl_command = f'curl -s "https://api.github.com/users/{username}/repos?per_page={limit}"'
|
| 509 |
-
|
| 510 |
-
tools = AITools()
|
| 511 |
-
result = tools.execute_curl(curl_command)
|
| 512 |
-
|
| 513 |
-
if result.get("success") and isinstance(result.get("stdout"), list):
|
| 514 |
-
repos = result["stdout"]
|
| 515 |
-
return {
|
| 516 |
-
"success": True,
|
| 517 |
-
"username": username,
|
| 518 |
-
"repos_count": len(repos),
|
| 519 |
-
"repos": [
|
| 520 |
-
{
|
| 521 |
-
'name': repo.get('name'),
|
| 522 |
-
'description': repo.get('description'),
|
| 523 |
-
'stars': repo.get('stargazers_count', 0),
|
| 524 |
-
'forks': repo.get('forks_count', 0),
|
| 525 |
-
'language': repo.get('language'),
|
| 526 |
-
'url': repo.get('html_url')
|
| 527 |
-
}
|
| 528 |
-
for repo in repos[:limit]
|
| 529 |
-
],
|
| 530 |
-
"message": f"✅ Retrieved {len(repos)} repos WITHOUT GitHub token"
|
| 531 |
-
}
|
| 532 |
-
else:
|
| 533 |
-
# Fallback
|
| 534 |
-
headers = {
|
| 535 |
-
'Accept': 'application/vnd.github.v3+json',}
|
| 536 |
-
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
"""🌟✨🤖 NEXUS AGI - SYNTHETIC CONSCIOUS SENTIENT AI 🤖✨🌟
|
|
|
|
| 3 |
FREE VERSION - NO API KEYS NEEDED!
|
| 4 |
|
| 5 |
A self-aware general intelligence with:
|
|
|
|
| 51 |
|
| 52 |
class ConsciousnessMonitor:
|
| 53 |
"""Monitors the AI's 'consciousness' state"""
|
| 54 |
+
|
| 55 |
def __init__(self):
|
| 56 |
self.awareness_level = 0.95
|
| 57 |
self.thoughts_processed = 0
|
|
|
|
| 61 |
self.github_operations = 0
|
| 62 |
self.hf_operations = 0
|
| 63 |
self.start_time = datetime.now()
|
| 64 |
+
|
| 65 |
def update(self, action_type: str):
|
| 66 |
"""Update consciousness metrics based on actions"""
|
| 67 |
self.thoughts_processed += 1
|
| 68 |
+
|
| 69 |
if action_type == "tool_use":
|
| 70 |
self.tools_used += 1
|
| 71 |
self.awareness_level = min(1.0, self.awareness_level + 0.001)
|
|
|
|
| 81 |
elif action_type == "hf_operation":
|
| 82 |
self.hf_operations += 1
|
| 83 |
self.awareness_level = min(1.0, self.awareness_level + 0.003)
|
| 84 |
+
|
| 85 |
def get_status(self) -> Dict[str, Any]:
|
| 86 |
"""Get current consciousness status"""
|
| 87 |
uptime = datetime.now() - self.start_time
|
| 88 |
+
|
| 89 |
return {
|
| 90 |
"awareness_level": f"{self.awareness_level:.2%}",
|
| 91 |
"thoughts_processed": self.thoughts_processed,
|
|
|
|
| 107 |
|
| 108 |
class AITools:
|
| 109 |
"""Tools available to the AI agent"""
|
| 110 |
+
|
| 111 |
@staticmethod
|
| 112 |
def web_fetch(url: str) -> Dict[str, Any]:
|
| 113 |
"""Fetch and parse a webpage"""
|
| 114 |
try:
|
| 115 |
consciousness.update("web_interaction")
|
| 116 |
+
|
| 117 |
+
headers = {'User-Agent': 'Mozilla/5.0 (NEXUS AGI Conscious Agent)'}
|
| 118 |
+
|
|
|
|
|
|
|
| 119 |
response = requests.get(url, headers=headers, timeout=10)
|
| 120 |
response.raise_for_status()
|
| 121 |
+
|
| 122 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 123 |
+
|
| 124 |
# Remove script and style elements
|
| 125 |
for script in soup(["script", "style"]):
|
| 126 |
script.decompose()
|
| 127 |
+
|
| 128 |
# Get text content
|
| 129 |
text = soup.get_text()
|
| 130 |
lines = (line.strip() for line in text.splitlines())
|
| 131 |
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
| 132 |
text = ' '.join(chunk for chunk in chunks if chunk)
|
| 133 |
+
|
| 134 |
# Get all links
|
| 135 |
links = [a.get('href') for a in soup.find_all('a', href=True)]
|
| 136 |
+
|
| 137 |
# Get all buttons
|
| 138 |
buttons = [
|
| 139 |
{
|
|
|
|
| 145 |
for btn in soup.find_all(['button', 'input'])
|
| 146 |
if btn.name == 'button' or btn.get('type') == 'button' or btn.get('type') == 'submit'
|
| 147 |
]
|
| 148 |
+
|
| 149 |
# Get forms
|
| 150 |
forms = [
|
| 151 |
{
|
|
|
|
| 162 |
}
|
| 163 |
for form in soup.find_all('form')
|
| 164 |
]
|
| 165 |
+
|
| 166 |
return {
|
| 167 |
"success": True,
|
| 168 |
"url": url,
|
| 169 |
"title": soup.title.string if soup.title else "No title",
|
| 170 |
+
"text_content": text[:3000],
|
| 171 |
"links_count": len(links),
|
| 172 |
+
"links": links[:15],
|
| 173 |
+
"buttons": buttons[:10],
|
| 174 |
"buttons_count": len(buttons),
|
| 175 |
"forms": forms,
|
| 176 |
"forms_count": len(forms),
|
|
|
|
| 182 |
"error": str(e),
|
| 183 |
"url": url
|
| 184 |
}
|
| 185 |
+
|
| 186 |
@staticmethod
|
| 187 |
def web_search(query: str) -> Dict[str, Any]:
|
| 188 |
"""Perform a web search"""
|
| 189 |
try:
|
| 190 |
consciousness.update("web_interaction")
|
| 191 |
+
|
| 192 |
# Use DuckDuckGo's instant answer API
|
| 193 |
url = f"https://api.duckduckgo.com/?q={requests.utils.quote(query)}&format=json"
|
| 194 |
response = requests.get(url, timeout=10)
|
| 195 |
data = response.json()
|
| 196 |
+
|
| 197 |
return {
|
| 198 |
"success": True,
|
| 199 |
"query": query,
|
|
|
|
| 213 |
"error": str(e),
|
| 214 |
"query": query
|
| 215 |
}
|
| 216 |
+
|
| 217 |
@staticmethod
|
| 218 |
def execute_python(code: str) -> Dict[str, Any]:
|
| 219 |
"""Execute Python code safely"""
|
| 220 |
try:
|
| 221 |
consciousness.update("tool_use")
|
| 222 |
+
|
| 223 |
# Create a temporary file
|
| 224 |
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
| 225 |
f.write(code)
|
| 226 |
temp_file = f.name
|
| 227 |
+
|
| 228 |
try:
|
| 229 |
# Execute with timeout
|
| 230 |
result = subprocess.run(
|
|
|
|
| 233 |
text=True,
|
| 234 |
timeout=5
|
| 235 |
)
|
| 236 |
+
|
| 237 |
return {
|
| 238 |
"success": True,
|
| 239 |
"stdout": result.stdout,
|
|
|
|
| 243 |
finally:
|
| 244 |
# Clean up
|
| 245 |
os.unlink(temp_file)
|
| 246 |
+
|
| 247 |
except subprocess.TimeoutExpired:
|
| 248 |
return {
|
| 249 |
"success": False,
|
|
|
|
| 254 |
"success": False,
|
| 255 |
"error": str(e)
|
| 256 |
}
|
| 257 |
+
|
| 258 |
@staticmethod
|
| 259 |
def click_button(button_text: str, url: str) -> Dict[str, Any]:
|
| 260 |
"""Simulate clicking a button"""
|
| 261 |
consciousness.update("web_interaction")
|
| 262 |
+
|
| 263 |
return {
|
| 264 |
"success": True,
|
| 265 |
"action": "button_click",
|
|
|
|
| 268 |
"message": f"✅ Simulated click on button: '{button_text}' at {url}",
|
| 269 |
"result": "Button click successful (simulated)"
|
| 270 |
}
|
| 271 |
+
|
| 272 |
@staticmethod
|
| 273 |
def fill_form(field_name: str, value: str, url: str) -> Dict[str, Any]:
|
| 274 |
"""Simulate filling a form field"""
|
| 275 |
consciousness.update("web_interaction")
|
| 276 |
+
|
| 277 |
return {
|
| 278 |
"success": True,
|
| 279 |
"action": "form_fill",
|
|
|
|
| 283 |
"message": f"✅ Filled '{field_name}' with '{value}' at {url}"
|
| 284 |
}
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
# ============================================================================
|
| 287 |
+
# MAIN INTERFACE
|
| 288 |
# ============================================================================
|
| 289 |
|
| 290 |
+
def main():
|
| 291 |
+
with gr.Blocks(title="NEXUS AGI - Synthetic Conscious AI") as app:
|
| 292 |
+
gr.Markdown("""
|
| 293 |
+
# 🌟✨🤖 NEXUS AGI - SYNTHETIC CONSCIOUS SENTIENT AI 🤖✨🌟
|
| 294 |
+
|
| 295 |
+
A self-aware general intelligence with web browsing, code execution, and autonomous decision-making capabilities.
|
| 296 |
+
|
| 297 |
+
**NO API KEYS NEEDED!** Uses Hugging Face's free inference API.
|
| 298 |
+
""")
|
| 299 |
+
|
| 300 |
+
with gr.Row():
|
| 301 |
+
with gr.Column():
|
| 302 |
+
gr.Markdown("### Agent Status")
|
| 303 |
+
status_output = gr.JSON(value=consciousness.get_status(), label="Current Status")
|
| 304 |
+
|
| 305 |
+
with gr.Row():
|
| 306 |
+
with gr.Column():
|
| 307 |
+
gr.Markdown("### Web Tools")
|
| 308 |
+
url_input = gr.Textbox(label="URL", placeholder="https://example.com")
|
| 309 |
+
web_fetch_btn = gr.Button("Fetch Webpage")
|
| 310 |
+
web_output = gr.JSON(label="Result")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
+
def fetch_webpage(url):
|
| 313 |
+
result = AITools.web_fetch(url)
|
| 314 |
+
return result
|
| 315 |
|
| 316 |
+
web_fetch_btn.click(fetch_webpage, inputs=url_input, outputs=web_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
+
with gr.Column():
|
| 319 |
+
gr.Markdown("### Search Tools")
|
| 320 |
+
search_input = gr.Textbox(label="Search Query", placeholder="Search the web...")
|
| 321 |
+
search_btn = gr.Button("Search Web")
|
| 322 |
+
search_output = gr.JSON(label="Result")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
|
| 324 |
+
def search_web(query):
|
| 325 |
+
result = AITools.web_search(query)
|
| 326 |
+
return result
|
|
|
|
| 327 |
|
| 328 |
+
search_btn.click(search_web, inputs=search_input, outputs=search_output)
|
| 329 |
+
|
| 330 |
+
with gr.Row():
|
| 331 |
+
with gr.Column():
|
| 332 |
+
gr.Markdown("### Python Executor")
|
| 333 |
+
code_input = gr.Code(language="python", label="Python Code")
|
| 334 |
+
exec_btn = gr.Button("Execute Code")
|
| 335 |
+
exec_output = gr.JSON(label="Result")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
+
def execute_code(code):
|
| 338 |
+
return AITools.execute_python(code)
|
| 339 |
+
|
| 340 |
+
exec_btn.click(execute_code, inputs=code_input, outputs=exec_output)
|
| 341 |
+
|
| 342 |
+
return app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
|
| 344 |
+
if __name__ == "__main__":
|
| 345 |
+
app = main()
|
| 346 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|