Upload 6 files
Browse files- README.md +6 -3
- agent3m.py +61 -0
- agentgen.py +44 -0
- main.py +10 -0
- model.py +12 -0
- tools.py +67 -0
README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Agent-3Web
|
| 2 |
+
|
| 3 |
+
Agent-3Web is an AGI agent designed to perform a wide range of tasks, including web browsing, file management, and more. It is built using python and integrates with various tools to enhance its capabilities.
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
Agent3Web focuses on building websites and progressive web apps, and it should not be used for any other software as it is designed particularly for web development tasks.
|
agent3m.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
import requests
|
| 4 |
+
from tqdm import tqdm
|
| 5 |
+
from model import ask
|
| 6 |
+
from agentgen import create_image
|
| 7 |
+
from tools import *
|
| 8 |
+
|
| 9 |
+
if not os.path.exists("agent"):
|
| 10 |
+
os.makedirs("agent")
|
| 11 |
+
|
| 12 |
+
def save_to_file(filename, file_content):
|
| 13 |
+
|
| 14 |
+
if not filename.startswith("agent/"):
|
| 15 |
+
filename = os.path.join("agent", filename)
|
| 16 |
+
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
| 17 |
+
|
| 18 |
+
print(f"Creating file: {filename}")
|
| 19 |
+
|
| 20 |
+
with open(filename, "w", encoding="utf-8") as file:
|
| 21 |
+
file.write(file_content)
|
| 22 |
+
|
| 23 |
+
print(f"File {filename} created successfully.")
|
| 24 |
+
|
| 25 |
+
def parse_and_run(response):
|
| 26 |
+
code_blocks = re.findall(r'```python(.*?)```', response, re.DOTALL)
|
| 27 |
+
for block in tqdm(code_blocks, desc="Executing Code Blocks", unit="block"):
|
| 28 |
+
code = block.strip()
|
| 29 |
+
try:
|
| 30 |
+
exec(code, globals())
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"\nError executing code block:\n{code}\n\nException: {e}")
|
| 33 |
+
|
| 34 |
+
auto_detect_html_and_link_css()
|
| 35 |
+
|
| 36 |
+
def run_agent(task):
|
| 37 |
+
build_robotstxt_file()
|
| 38 |
+
build_license_file()
|
| 39 |
+
build_css_file()
|
| 40 |
+
|
| 41 |
+
system_prompt = f"""
|
| 42 |
+
You are an AI agent, your response must be in python code, using only the following functions:
|
| 43 |
+
save_to_file(filename,file_content)
|
| 44 |
+
create_image(filename, prompt)
|
| 45 |
+
|
| 46 |
+
save_to_file() saves a file with the given filename and content.
|
| 47 |
+
create_image() creates an image with the given filename and prompt. for example as prompt you can use "A beautiful landscape with mountains and a river", or any image you want.
|
| 48 |
+
Based on this task: {task}, make all the files. These are the files you need to create:
|
| 49 |
+
- A file named "index.html" with the HTML content.
|
| 50 |
+
- A file named "style.css" with the CSS content.
|
| 51 |
+
- A file named "script.js" with the JavaScript content or just console.log("app started") if no JS is needed.
|
| 52 |
+
- An image file named "logo.png" with the logo image.
|
| 53 |
+
- A README.md file with a description of the project and how to run it.
|
| 54 |
+
- Any other files you deem necessary for the project.
|
| 55 |
+
|
| 56 |
+
Your task is:
|
| 57 |
+
{task}
|
| 58 |
+
"""
|
| 59 |
+
print("\nSending task to agent...\n")
|
| 60 |
+
response = ask(system_prompt)
|
| 61 |
+
parse_and_run(response)
|
agentgen.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
import requests
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
def create_image(filename, prompt):
|
| 8 |
+
print(f"Creating image: {filename}")
|
| 9 |
+
prompt = re.sub(r'\s+', ' ', prompt).strip()
|
| 10 |
+
|
| 11 |
+
url = f"https://pollinations.ai/p/{prompt}?seed=2025&nologo=true&model=flux&width=1080&height=1080"
|
| 12 |
+
response = requests.get(url)
|
| 13 |
+
original_image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 14 |
+
|
| 15 |
+
base_filename = os.path.splitext(filename)[0]
|
| 16 |
+
save_path = os.path.join("agent", f"{base_filename}_1080.png")
|
| 17 |
+
os.makedirs("agent", exist_ok=True)
|
| 18 |
+
original_image.save(save_path)
|
| 19 |
+
print(f"Saved original image: {save_path}")
|
| 20 |
+
|
| 21 |
+
original_path = os.path.join("agent", filename)
|
| 22 |
+
original_image.save(original_path)
|
| 23 |
+
print(f"Saved original image as: {original_path}")
|
| 24 |
+
|
| 25 |
+
sizes = {
|
| 26 |
+
"512": (512, 512),
|
| 27 |
+
"192": (192, 192),
|
| 28 |
+
"48": (48, 48),
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
for size_label, size in sizes.items():
|
| 32 |
+
resized = original_image.resize(size, Image.LANCZOS)
|
| 33 |
+
resized_filename = os.path.join("agent", f"{base_filename}_{size_label}.png")
|
| 34 |
+
resized.save(resized_filename)
|
| 35 |
+
print(f"Saved resized image: {resized_filename}")
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
filename = "example_image.png" # Default filename, can be changed
|
| 39 |
+
prompt = "A beautiful landscape with mountains and a river" # Default prompt, can be changed
|
| 40 |
+
|
| 41 |
+
if filename and prompt:
|
| 42 |
+
create_image(filename, prompt)
|
| 43 |
+
else:
|
| 44 |
+
print("Filename and prompt cannot be empty.")
|
main.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from agent3m import *
|
| 2 |
+
|
| 3 |
+
print("What website or web app would you like me to work on? Please describe the task thoroughly.")
|
| 4 |
+
|
| 5 |
+
task_input = input("> ").strip()
|
| 6 |
+
if task_input:
|
| 7 |
+
run_agent(task_input)
|
| 8 |
+
print("\nAgent-3Web has completed the task.")
|
| 9 |
+
else:
|
| 10 |
+
print("No task provided, sir.")
|
model.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
def ask(prompt: str) -> str:
|
| 4 |
+
url = "http://text.pollinations.ai/"
|
| 5 |
+
fullurl = url + prompt.replace(" ", "%20")
|
| 6 |
+
response = requests.get(fullurl)
|
| 7 |
+
return response.text
|
| 8 |
+
|
| 9 |
+
if __name__ == "__main__":
|
| 10 |
+
prompt = "What is the capital of France?"
|
| 11 |
+
response = ask(prompt)
|
| 12 |
+
print("Response:", response)
|
tools.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def save_to_file(filename, file_content):
|
| 5 |
+
|
| 6 |
+
if not filename.startswith("agent/"):
|
| 7 |
+
filename = os.path.join("agent", filename)
|
| 8 |
+
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
| 9 |
+
|
| 10 |
+
print(f"Creating file: {filename}")
|
| 11 |
+
|
| 12 |
+
with open(filename, "w", encoding="utf-8") as file:
|
| 13 |
+
file.write(file_content)
|
| 14 |
+
|
| 15 |
+
print(f"File {filename} created successfully.")
|
| 16 |
+
|
| 17 |
+
def build_robotstxt_file():
|
| 18 |
+
content = "User-agent: *\nDisallow: /"
|
| 19 |
+
save_to_file("agent/robots.txt", content)
|
| 20 |
+
|
| 21 |
+
def build_license_file():
|
| 22 |
+
year = datetime.now().year
|
| 23 |
+
content = f'''
|
| 24 |
+
|
| 25 |
+
Copyright {year} Agent-3Web
|
| 26 |
+
|
| 27 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 28 |
+
|
| 29 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 30 |
+
|
| 31 |
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 32 |
+
|
| 33 |
+
'''
|
| 34 |
+
save_to_file("agent/LICENSE", content)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def build_css_file():
|
| 38 |
+
content = """
|
| 39 |
+
/*======================================
|
| 40 |
+
= Base Reset Styles =
|
| 41 |
+
======================================*/
|
| 42 |
+
|
| 43 |
+
html, body {
|
| 44 |
+
margin: 0;
|
| 45 |
+
padding: 0;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
"""
|
| 49 |
+
save_to_file("agent/s.css", content)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def auto_detect_html_and_link_css():
|
| 53 |
+
html_dir = "agent"
|
| 54 |
+
css_link = '<link rel="stylesheet" href="s.css">\n'
|
| 55 |
+
|
| 56 |
+
for filename in os.listdir(html_dir):
|
| 57 |
+
if filename.endswith(".html"):
|
| 58 |
+
filepath = os.path.join(html_dir, filename)
|
| 59 |
+
with open(filepath, "r", encoding="utf-8") as f:
|
| 60 |
+
content = f.read()
|
| 61 |
+
if css_link.strip() not in content:
|
| 62 |
+
if "</head>" in content:
|
| 63 |
+
content = content.replace("</head>", f"{css_link}</head>")
|
| 64 |
+
else:
|
| 65 |
+
content = css_link + content
|
| 66 |
+
with open(filepath, "w", encoding="utf-8") as f:
|
| 67 |
+
f.write(content)
|