acecalisto3 commited on
Commit
2fd03cf
·
verified ·
1 Parent(s): 93ea710

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +141 -327
app.py CHANGED
@@ -1,84 +1,47 @@
 
 
1
  import os
 
2
  import subprocess
3
- from huggingface_hub import InferenceClient
4
- import gradio as gr
5
- import random
6
- import prompts
7
  import time
8
- from typing import List, Dict
9
- from .dictionary import corpora, models
10
- from gensim.summarization import summarize
11
-
12
- # Simulated agent and tool libraries
13
- AGENT_TYPES = [
14
- "Task Executor",
15
- "Information Retriever",
16
- "Decision Maker",
17
- "Data Analyzer",
18
- ]
19
- TOOL_TYPES = [
20
- "Web Scraper",
21
- "Database Connector",
22
- "API Caller",
23
- "File Handler",
24
- "Text Processor",
25
- ]
26
-
27
- # Initialize Hugging Face client
28
- client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
29
-
30
- VERBOSE = False
31
- MAX_HISTORY = 100
32
- MODEL = "mistralai/Mixtral-8x7B-Instruct-v0.1"
33
-
34
- # Import necessary prompts and functions from the existing code
35
- from prompts import (
36
- ACTION_PROMPT,
37
- ADD_PROMPT,
38
- COMPRESS_HISTORY_PROMPT,
39
- LOG_PROMPT,
40
- LOG_RESPONSE,
41
- MODIFY_PROMPT,
42
- PREFIX,
43
- READ_PROMPT,
44
- TASK_PROMPT,
45
- UNDERSTAND_TEST_RESULTS_PROMPT,
46
- )
47
- from .utils import parse_action, parse_file_content, read_python_module_structure
48
- from flask import Flask, request, jsonify
49
 
 
 
50
 
51
  class Agent:
52
  def __init__(self, name: str, agent_type: str, complexity: int):
53
- self.name = name
54
- self.type = agent_type
55
- self.complexity = complexity
56
- self.tools = []
57
 
58
- def add_tool(self, tool):
59
  self.tools.append(tool)
60
 
61
  def __str__(self):
62
- return f"{self.name} ({self.type}) - Complexity: {self.complexity}"
63
-
64
 
65
  class Tool:
66
  def __init__(self, name: str, tool_type: str):
67
- self.name = name
68
- self.type = tool_type
69
 
70
  def __str__(self):
71
- return f"{self.name} ({self.type})"
72
-
73
 
74
  class Pypelyne:
75
  def __init__(self):
76
  self.agents: List[Agent] = []
77
  self.tools: List[Tool] = []
78
- self.history = ""
79
- self.task = None
80
- self.purpose = None
81
- self.directory = None
 
82
 
83
  def add_agent(self, agent: Agent):
84
  self.agents.append(agent)
@@ -86,28 +49,29 @@ class Pypelyne:
86
  def add_tool(self, tool: Tool):
87
  self.tools.append(tool)
88
 
89
- def generate_chat_app(self):
90
- time.sleep(2) # Simulate processing time
91
  return f"Chat app generated with {len(self.agents)} agents and {len(self.tools)} tools."
92
 
93
- def run_gpt(self, prompt_template, stop_tokens, max_tokens, **prompt_kwargs):
94
- content = PREFIX.format(
95
- module_summary=read_python_module_structure(self.directory)[0],
96
- purpose=self.purpose,
97
- ) + prompt_template.format(**prompt_kwargs)
 
 
 
 
98
 
99
  if VERBOSE:
100
  print(LOG_PROMPT.format(content))
101
 
102
- stream = client.text_generation(
103
- prompt=content,
104
- max_new_tokens=max_tokens,
105
- stop_sequences=stop_tokens if stop_tokens else None,
106
- do_sample=True,
107
- temperature=0.7,
108
- )
109
-
110
- resp = "".join(token for token in stream)
111
 
112
  if VERBOSE:
113
  print(LOG_RESPONSE.format(resp))
@@ -123,37 +87,29 @@ class Pypelyne:
123
  )
124
  self.history = f"observation: {resp}\n"
125
 
126
- def run_action(self, action_name, action_input):
127
  if action_name == "COMPLETE":
128
  return "Task completed."
129
 
130
  if len(self.history.split("\n")) > MAX_HISTORY:
131
- if VERBOSE:
132
- print("COMPRESSING HISTORY")
133
  self.compress_history()
134
 
135
- action_funcs = {
136
- "MAIN": self.call_main,
137
- "UPDATE-TASK": self.call_set_task,
138
- "MODIFY-FILE": self.call_modify,
139
- "READ-FILE": self.call_read,
140
- "ADD-FILE": self.call_add,
141
- "TEST": self.call_test,
142
- }
143
 
144
- if action_name not in action_funcs:
145
- return f"Unknown action: {action_name}"
 
 
146
 
147
- print(f"RUN: {action_name} {action_input}")
148
- return action_funcs[action_name](action_input)
149
-
150
- def call_main(self, action_input):
151
  resp = self.run_gpt(
152
- ACTION_PROMPT,
153
  stop_tokens=["observation:", "task:"],
154
  max_tokens=256,
155
  task=self.task,
156
  history=self.history,
 
157
  )
158
  lines = resp.strip().strip("\n").split("\n")
159
  for line in lines:
@@ -161,276 +117,134 @@ class Pypelyne:
161
  continue
162
  if line.startswith("thought: "):
163
  self.history += f"{line}\n"
164
- elif line.startswith("action: "):
165
  action_name, action_input = parse_action(line)
166
- self.history += f"{line}\n"
167
- return self.run_action(action_name, action_input)
168
  return "No valid action found."
169
 
170
- def call_set_task(self, action_input):
171
- self.task = self.run_gpt(
172
- TASK_PROMPT,
173
- stop_tokens=[],
174
- max_tokens=64,
175
- task=self.task,
176
- history=self.history,
177
- ).strip("\n")
178
- self.history += f"observation: task has been updated to: {self.task}\n"
179
  return f"Task updated: {self.task}"
180
 
181
- def call_modify(self, action_input):
182
- if not os.path.exists(action_input):
183
- self.history += "observation: file does not exist\n"
184
- return "File does not exist."
185
-
186
- content = read_python_module_structure(self.directory)[1]
187
- f_content = (
188
- content[action_input] if content[action_input] else "< document is empty >"
189
- )
190
 
191
  resp = self.run_gpt(
192
- MODIFY_PROMPT,
193
  stop_tokens=["action:", "thought:", "observation:"],
194
  max_tokens=2048,
195
  task=self.task,
196
  history=self.history,
197
  file_path=action_input,
198
- file_contents=f_content,
 
199
  )
200
- new_contents, description = parse_file_content(resp)
201
- if new_contents is None:
202
- self.history += "observation: failed to modify file\n"
203
- return "Failed to modify file."
204
 
205
- with open(action_input, "w") as f:
206
- f.write(new_contents)
207
 
208
  self.history += f"observation: file successfully modified\n"
209
- self.history += f"observation: {description}\n"
210
  return f"File modified: {action_input}"
211
 
212
- def call_read(self, action_input):
213
- if not os.path.exists(action_input):
214
- self.history += "observation: file does not exist\n"
215
- return "File does not exist."
216
 
217
- content = read_python_module_structure(self.directory)[1]
218
- f_content = (
219
- content[action_input] if content[action_input] else "< document is empty >"
220
- )
221
 
222
- resp = self.run_gpt(
223
- READ_PROMPT,
224
- stop_tokens=[],
225
- max_tokens=256,
226
- task=self.task,
227
- history=self.history,
228
- file_path=action_input,
229
- file_contents=f_content,
230
- ).strip("\n")
231
- self.history += f"observation: {resp}\n"
232
- return f"File read: {action_input}"
233
-
234
- def call_add(self, action_input):
235
- d = os.path.dirname(action_input)
236
- if not d.startswith(self.directory):
237
- self.history += (
238
- f"observation: files must be under directory {self.directory}\n"
239
- )
240
- return f"Invalid directory: {d}"
241
- elif not action_input.endswith(".py"):
242
- self.history += "observation: can only write .py files\n"
243
- return "Only .py files are allowed."
244
- else:
245
- if d and not os.path.exists(d):
246
- os.makedirs(d)
247
- if not os.path.exists(action_input):
248
- resp = self.run_gpt(
249
- ADD_PROMPT,
250
- stop_tokens=["action:", "thought:", "observation:"],
251
- max_tokens=2048,
252
- task=self.task,
253
- history=self.history,
254
- file_path=action_input,
255
- )
256
- new_contents, description = parse_file_content(resp)
257
- if new_contents is None:
258
- self.history += "observation: failed to write file\n"
259
- return "Failed to write file."
260
-
261
- with open(action_input, "w") as f:
262
- f.write(new_contents)
263
-
264
- self.history += "observation: file successfully written\n"
265
- self.history += f"observation: {description}\n"
266
- return f"File added: {action_input}"
267
- else:
268
- self.history += "observation: file already exists\n"
269
- return "File already exists."
270
-
271
- def call_test(self, action_input):
272
- result = subprocess.run(
273
- ["python", "-m", "pytest", "--collect-only", self.directory],
274
- capture_output=True,
275
- text=True,
276
- )
277
- if result.returncode != 0:
278
- self.history += f"observation: there are no tests! Test should be written in a test folder under {self.directory}\n"
279
- return "No tests found."
280
- result = subprocess.run(
281
- ["python", "-m", "pytest", self.directory], capture_output=True, text=True
282
- )
283
- if result.returncode == 0:
284
- self.history += "observation: tests pass\n"
285
- return "All tests passed."
286
 
287
- resp = self.run_gpt(
288
- UNDERSTAND_TEST_RESULTS_PROMPT,
289
- stop_tokens=[],
290
- max_tokens=256,
291
- task=self.task,
292
- history=self.history,
293
- stdout=result.stdout[:5000],
294
- stderr=result.stderr[:5000],
295
- )
296
- self.history += f"observation: tests failed: {resp}\n"
297
- return f"Tests failed: {resp}"
298
 
 
 
299
 
300
- pypelyne = Pypelyne()
 
 
301
 
 
 
302
 
303
- def create_agent(name: str, agent_type: str, complexity: int) -> str:
 
 
 
 
304
  agent = Agent(name, agent_type, complexity)
305
  pypelyne.add_agent(agent)
306
- return f"Agent created: {agent}"
307
 
308
- def create_tool(name: str, tool_type: str) -> str:
309
  tool = Tool(name, tool_type)
310
  pypelyne.add_tool(tool)
311
- return f"Tool created: {tool}"
312
-
313
- def assign_tool(agent_name: str, tool_name: str) -> str:
314
- agent = next((a for a in pypelyne.agents if a.name == agent_name), None)
315
- tool = next((t for t in pypelyne.tools if t.name == tool_name), None)
316
 
317
- if agent and tool:
318
- agent.add_tool(tool)
319
- return f"Tool '{tool.name}' assigned to agent '{agent.name}'"
320
- else:
321
- return "Agent or tool not found."
322
 
323
- def generate_chat_app() -> str:
324
- return pypelyne.generate_chat_app()
325
-
326
- def list_agents() -> str:
327
- return (
328
- "\n".join(str(agent) for agent in pypelyne.agents) or "No agents created yet."
329
  )
330
-
331
- def list_tools() -> str:
332
- return "\n".join(str(tool) for tool in pypelyne.tools) or "No tools created yet."
333
-
334
- def chat_with_pypelyne(message: str) -> str:
335
- return pypelyne.run_action("MAIN", message)
336
-
337
- def set_purpose_and_directory(purpose: str, directory: str) -> str:
338
- pypelyne.purpose = purpose
339
  pypelyne.directory = directory
340
- return f"Purpose set to: {purpose}\nWorking directory set to: {directory}"
341
-
342
- with gr.Blocks() as app:
343
- gr.Markdown("# Welcome to Pypelyne")
344
- gr.Markdown("Create your custom pipeline with agents and tools, then chat with it!")
345
-
346
- with gr.Tab("Setup"):
347
- purpose_input = gr.Textbox(label="Set Purpose")
348
- directory_input = gr.Textbox(label="Set Working Directory")
349
- setup_btn = gr.Button("Set Purpose and Directory")
350
- setup_output = gr.Textbox(label="Setup Output")
351
- setup_btn.click(
352
- set_purpose_and_directory,
353
- inputs=[purpose_input, directory_input],
354
- outputs=setup_output,
355
- )
356
 
357
- with gr.Tab("Create Agents"):
358
- agent_name = gr.Textbox(label="Agent Name")
359
- agent_type = gr.Dropdown(choices=AGENT_TYPES, label="Agent Type")
360
- agent_complexity = gr.Slider(
361
- minimum=1, maximum=10, step=1, label="Agent Complexity"
362
- )
363
- create_agent_btn = gr.Button("Create Agent")
364
- agent_output = gr.Textbox(label="Output")
365
- create_agent_btn.click(
366
- create_agent,
367
- inputs=[agent_name, agent_type, agent_complexity],
368
- outputs=agent_output,
369
- )
370
-
371
- with gr.Tab("Create Tools"):
372
- tool_name = gr.Textbox(label="Tool Name")
373
- tool_type = gr.Dropdown(choices=TOOL_TYPES, label="Tool Type")
374
- create_tool_btn = gr.Button("Create Tool")
375
- tool_output = gr.Textbox(label="Output")
376
- create_tool_btn.click(
377
- create_tool, inputs=[tool_name, tool_type], outputs=tool_output
378
- )
379
-
380
- with gr.Tab("Assign Tools"):
381
- agent_select = gr.Dropdown(choices=[], label="Select Agent")
382
- tool_select = gr.Dropdown(choices=[], label="Select Tool")
383
- assign_tool_btn = gr.Button("Assign Tool")
384
- assign_output = gr.Textbox(label="Output")
385
- assign_tool_btn.click(
386
- assign_tool, inputs=[agent_select, tool_select], outputs=assign_output
387
- )
388
-
389
- with gr.Tab("Generate Chat App"):
390
- generate_btn = gr.Button("Generate Chat App")
391
- generate_output = gr.Textbox(label="Output")
392
- generate_btn.click(generate_chat_app, outputs=generate_output)
393
-
394
- with gr.Tab("Chat with Pypelyne"):
395
- chat_input = gr.Textbox(label="Your Message")
396
- chat_output = gr.Textbox(label="Pypelyne's Response")
397
- chat_btn = gr.Button("Send")
398
- chat_btn.click(chat_with_pypelyne, inputs=chat_input, outputs=chat_output)
399
 
400
- with gr.Tab("View Pypelyne"):
401
- view_agents_btn = gr.Button("View Agents")
402
- view_tools_btn = gr.Button("View Tools")
403
- view_output = gr.Textbox(label="Pypelyne Components")
404
- view_agents_btn.click(list_agents, outputs=view_output)
405
- view_tools_btn.click(list_tools, outputs=view_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
 
407
- def update_dropdowns():
408
- return gr.Dropdown.update(
409
- choices=[agent.name for agent in pypelyne.agents]
410
- ), gr.Dropdown.update(choices=[tool.name for tool in pypelyne.tools])
411
 
412
- create_agent_btn.click(update_dropdowns, outputs=[agent_select, tool_select])
413
- create_tool_btn.click(update_dropdowns, outputs=[agent_select, tool_select])
 
 
414
 
415
  if __name__ == "__main__":
416
- app.launch()
417
- app = Flask(__name__)
418
-
419
- @app.route("/chat", methods=["POST"])
420
- def chat():
421
- message = request.json["message"]
422
- response = chat_with_pypelyne(message)
423
- return jsonify({"response": response})
424
-
425
- @app.route("/agents", methods=["GET"])
426
- def get_agents():
427
- agents = list_agents()
428
- return jsonify({"agents": agents})
429
-
430
- @app.route("/tools", methods=["GET"])
431
- def get_tools():
432
- tools = list_tools()
433
- return jsonify({"tools": tools})
434
-
435
- if __name__ == "__main__":
436
- app.run()
 
1
+ from __future__ import annotations
2
+ from typing import List, Dict, Union
3
  import os
4
+ import re
5
  import subprocess
6
+ import streamlit as st
 
 
 
7
  import time
8
+ from langchain_core.prompts import PromptTemplate
9
+ from langchain_community.llms import HuggingFaceEndpoint
10
+ from huggingface_hub.inference_api import InferenceApi as InferenceClient
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Load LLM
13
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.1, "max_new_tokens": 500})
14
 
15
  class Agent:
16
  def __init__(self, name: str, agent_type: str, complexity: int):
17
+ self.name: str = name
18
+ self.agent_type: str = agent_type
19
+ self.complexity: int = complexity
20
+ self.tools: List[Tool] = []
21
 
22
+ def add_tool(self, tool: Tool):
23
  self.tools.append(tool)
24
 
25
  def __str__(self):
26
+ return f"{self.name} ({self.agent_type}) - Complexity: {self.complexity}"
 
27
 
28
  class Tool:
29
  def __init__(self, name: str, tool_type: str):
30
+ self.name: str = name
31
+ self.tool_type: str = tool_type
32
 
33
  def __str__(self):
34
+ return f"{self.name} ({self.tool_type})"
 
35
 
36
  class Pypelyne:
37
  def __init__(self):
38
  self.agents: List[Agent] = []
39
  self.tools: List[Tool] = []
40
+ self.history: str = ""
41
+ self.task: str = ""
42
+ self.purpose: str = ""
43
+ self.directory: str = ""
44
+ self.task_queue: list = []
45
 
46
  def add_agent(self, agent: Agent):
47
  self.agents.append(agent)
 
49
  def add_tool(self, tool: Tool):
50
  self.tools.append(tool)
51
 
52
+ def generate_chat_app(self) -> str:
53
+ time.sleep(2)
54
  return f"Chat app generated with {len(self.agents)} agents and {len(self.tools)} tools."
55
 
56
+ def run_gpt(
57
+ self,
58
+ prompt_template: PromptTemplate,
59
+ stop_tokens: List[str],
60
+ max_tokens: int,
61
+ **prompt_kwargs,
62
+ ) -> str:
63
+ content = f"""{PREFIX}
64
+ {prompt_template.format(**prompt_kwargs)}"""
65
 
66
  if VERBOSE:
67
  print(LOG_PROMPT.format(content))
68
 
69
+ try:
70
+ stream = llm.predict(content)
71
+ resp = "".join(stream)
72
+ except Exception as e:
73
+ print(f"Error in run_gpt: {e}")
74
+ resp = f"Error: {e}"
 
 
 
75
 
76
  if VERBOSE:
77
  print(LOG_RESPONSE.format(resp))
 
87
  )
88
  self.history = f"observation: {resp}\n"
89
 
90
+ def run_action(self, action_name: str, action_input: Union[str, List[str]], tools: List[Tool] = None) -> str:
91
  if action_name == "COMPLETE":
92
  return "Task completed."
93
 
94
  if len(self.history.split("\n")) > MAX_HISTORY:
 
 
95
  self.compress_history()
96
 
97
+ if action_name not in self.task_queue:
98
+ self.task_queue.append(action_name)
 
 
 
 
 
 
99
 
100
+ task_function = getattr(self, f"call_{action_name.lower()}")
101
+ result = task_function(action_input, tools)
102
+ self.task_queue.pop(0)
103
+ return result
104
 
105
+ def call_main(self, action_input: List[str]) -> str:
 
 
 
106
  resp = self.run_gpt(
107
+ f"{ACTION_PROMPT}",
108
  stop_tokens=["observation:", "task:"],
109
  max_tokens=256,
110
  task=self.task,
111
  history=self.history,
112
+ actions=action_input,
113
  )
114
  lines = resp.strip().strip("\n").split("\n")
115
  for line in lines:
 
117
  continue
118
  if line.startswith("thought: "):
119
  self.history += f"{line}\n"
 
120
  action_name, action_input = parse_action(line)
121
+ self.run_action(action_name, action_input)
 
122
  return "No valid action found."
123
 
124
+ def call_set_task(self, action_input: str) -> str:
125
+ self.task = action_input
 
 
 
 
 
 
 
126
  return f"Task updated: {self.task}"
127
 
128
+ def call_modify(self, action_input: str, agent: Agent) -> str:
129
+ with open(action_input, "r") as file:
130
+ file_content = file.read()
 
 
 
 
 
 
131
 
132
  resp = self.run_gpt(
133
+ f"{MODIFY_PROMPT}",
134
  stop_tokens=["action:", "thought:", "observation:"],
135
  max_tokens=2048,
136
  task=self.task,
137
  history=self.history,
138
  file_path=action_input,
139
+ file_contents=file_content,
140
+ agent=agent,
141
  )
142
+ new_contents = resp.strip()
 
 
 
143
 
144
+ with open(action_input, "w") as file:
145
+ file.write(new_contents)
146
 
147
  self.history += f"observation: file successfully modified\n"
 
148
  return f"File modified: {action_input}"
149
 
150
+ def call_read(self, action_input: str) -> str:
151
+ with open(action_input, "r") as file:
152
+ file_content = file.read()
 
153
 
154
+ self.history += f"observation: {file_content}\n"
155
+ return file_content
 
 
156
 
157
+ def call_add(self, action_input: str) -> str:
158
+ if not os.path.exists(self.directory):
159
+ os.makedirs(self.directory)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
+ with open(os.path.join(self.directory, action_input), "w") as file:
162
+ file.write("")
 
 
 
 
 
 
 
 
 
163
 
164
+ self.history += f"observation: file created: {action_input}\n"
165
+ return f"File created: {action_input}"
166
 
167
+ def call_test(self, action_input: str) -> str:
168
+ result = subprocess.run(["python", os.path.join(self.directory, action_input)], capture_output=True, text=True)
169
+ error_message = result.stderr.strip()
170
 
171
+ self.history += f"observation: tests {('passed' if error_message == '' else 'failed')}\n"
172
+ return f"Tests {'passed' if error_message == '' else 'failed'}: {error_message}"
173
 
174
+ # Global Pypelyne Instance
175
+ pypelyne = Pypelyne()
176
+
177
+ # Helper Functions
178
+ def create_agent(name: str, agent_type: str, complexity: int) -> Agent:
179
  agent = Agent(name, agent_type, complexity)
180
  pypelyne.add_agent(agent)
181
+ return agent
182
 
183
+ def create_tool(name: str, tool_type: str) -> Tool:
184
  tool = Tool(name, tool_type)
185
  pypelyne.add_tool(tool)
186
+ return tool
 
 
 
 
187
 
188
+ # Streamlit App Code
189
+ def main():
190
+ st.title("🧠 Pypelyne: Your AI-Powered Coding Assistant")
 
 
191
 
192
+ # Settings
193
+ st.sidebar.title("⚙️ Settings")
194
+ directory = st.sidebar.text_input(
195
+ "Project Directory:", value=pypelyne.directory, help="Path to your coding project"
 
 
196
  )
 
 
 
 
 
 
 
 
 
197
  pypelyne.directory = directory
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
+ purpose = st.sidebar.text_area(
200
+ "Project Purpose:",
201
+ value=pypelyne.purpose,
202
+ help="Describe the purpose of your coding project.",
203
+ )
204
+ pypelyne.purpose = purpose
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
+ # Agent and Tool Management
207
+ st.sidebar.header("🤖 Agents")
208
+ agents = st.sidebar.column(2)
209
+ tools = st.sidebar.column(1)
210
+
211
+ for agent in pypelyne.agents:
212
+ agents.write(f"- {agent}")
213
+
214
+ if st.sidebar.button("Create New Agent"):
215
+ agent_name = st.sidebar.text_input("Agent Name:")
216
+ agent_type = st.sidebar.selectbox("Agent Type:", ["Task Executor", "Information Retriever", "Decision Maker", "Data Analyzer"])
217
+ agent_complexity = st.sidebar.slider("Complexity (1-5):", 1, 5, 3)
218
+ new_agent = create_agent(agent_name, agent_type, agent_complexity)
219
+ pypelyne.agents = pypelyne.agents + [new_agent]
220
+
221
+ st.sidebar.header("🛠️ Tools")
222
+ for tool in pypelyne.tools:
223
+ tools.write(f"- {tool}")
224
+
225
+ if st.sidebar.button("Create New Tool"):
226
+ tool_name = st.sidebar.text_input("Tool Name:")
227
+ tool_type = st.sidebar.selectbox("Tool Type:", ["Web Scraper", "Database Connector", "API Caller", "File Handler", "Text Processor"])
228
+ new_tool = create_tool(tool_name, tool_type)
229
+ pypelyne.tools = pypelyne.tools + [new_tool]
230
+
231
+ # Main Content Area
232
+ st.header("💻 Code Interaction")
233
+
234
+ task = st.text_area(
235
+ "🎯 Task:",
236
+ value=pypelyne.task,
237
+ help="Describe the coding task you want to perform.",
238
+ )
239
+ if task:
240
+ pypelyne.task = task
241
 
242
+ user_input = st.text_input("💬 Your Input:")
 
 
 
243
 
244
+ if st.button("Execute"):
245
+ if user_input:
246
+ response = pypelyne.run_action("main", [user_input])
247
+ st.write("Pypelyne Says: ", response)
248
 
249
  if __name__ == "__main__":
250
+ main()