acecalisto3 commited on
Commit
02f5e5f
·
verified ·
1 Parent(s): f8285bc

Update appaaa.py

Browse files
Files changed (1) hide show
  1. appaaa.py +59 -15
appaaa.py CHANGED
@@ -1,19 +1,63 @@
1
- import streamlit as st
2
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
 
 
 
3
 
4
- # Define the agent
5
- agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
 
6
 
7
- # Streamlit app title
8
- st.title("SmolAgents Streamlit App")
 
 
9
 
10
- # Input text box for user query
11
- user_query = st.text_input("Enter your query:")
 
12
 
13
- # Button to run the agent
14
- if st.button("Run Agent"):
15
- if user_query:
16
- result = agent.run(user_query)
17
- st.write("Result:", result)
18
- else:
19
- st.write("Please enter a query.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import random
4
+ import logging
5
+ from pathlib import Path
6
 
7
+ # Set up logging
8
+ logging.basicConfig(level=logging.INFO)
9
+ logger = logging.getLogger(__name__)
10
 
11
+ # Define the root directory for the application
12
+ ROOT_DIR = Path(__file__).parent
13
+ AGENTS_DIR = ROOT_DIR / "agents"
14
+ TOOLS_DIR = ROOT_DIR / "tools"
15
 
16
+ # Create directories if they do not exist
17
+ AGENTS_DIR.mkdir(exist_ok=True)
18
+ TOOLS_DIR.mkdir(exist_ok=True)
19
 
20
+ # Function to generate a new agent
21
+ def generate_agent(agent_name: str) -> str:
22
+ agent_code = f"""
23
+ class {agent_name}:
24
+ def __init__(self):
25
+ self.name = '{agent_name}'
26
+
27
+ def run(self):
28
+ print("Running {agent_name}...")
29
+ """
30
+ agent_file_path = AGENTS_DIR / f"{agent_name}.py"
31
+ with open(agent_file_path, 'w') as f:
32
+ f.write(agent_code)
33
+ logger.info(f"Generated agent: {agent_name} at {agent_file_path}")
34
+ return agent_file_path
35
+
36
+ # Function to generate a new tool
37
+ def generate_tool(tool_name: str) -> str:
38
+ tool_code = f"""
39
+ def {tool_name}():
40
+ print("Executing tool: {tool_name}")
41
+ """
42
+ tool_file_path = TOOLS_DIR / f"{tool_name}.py"
43
+ with open(tool_file_path, 'w') as f:
44
+ f.write(tool_code)
45
+ logger.info(f"Generated tool: {tool_name} at {tool_file_path}")
46
+ return tool_file_path
47
+
48
+ # Main loop to continuously generate agents and tools
49
+ def main():
50
+ while True:
51
+ # Randomly decide to generate an agent or a tool
52
+ if random.choice([True, False]):
53
+ agent_name = f"Agent{random.randint(1, 1000)}"
54
+ generate_agent(agent_name)
55
+ else:
56
+ tool_name = f"Tool{random.randint(1, 1000)}"
57
+ generate_tool(tool_name)
58
+
59
+ # Sleep for a while before generating the next agent/tool
60
+ time.sleep(5) # Adjust the sleep time as needed
61
+
62
+ if __name__ == "__main__":
63
+ main()