acecalisto3 commited on
Commit
3965990
1 Parent(s): 2da8d37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -11
app.py CHANGED
@@ -1,18 +1,69 @@
1
- import os
2
  import subprocess
3
- import random
 
 
 
 
4
  import json
5
- from datetime import datetime
6
- from huggingface_hub import InferenceClient, cached_download, hf_hub_url
7
- import gradio as gr
8
- from safe_search import safe_search
9
- from i_search import google, i_search as i_s
10
  from agent import (
11
- ACTION_PROMPT, ADD_PROMPT, COMPRESS_HISTORY_PROMPT, LOG_PROMPT,
12
- LOG_RESPONSE, MODIFY_PROMPT, PRE_PREFIX, SEARCH_QUERY, READ_PROMPT,
13
- TASK_PROMPT, UNDERSTAND_TEST_RESULTS_PROMPT
 
 
 
 
14
  )
15
- from utils import parse_action, parse_file_content, read_python_module_structure
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # Global Variables
18
  terminal_history = ""
 
 
1
  import subprocess
2
+ from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
3
+ import black
4
+ from pylint import lint
5
+ from io import StringIO
6
+ import os
7
  import json
8
+ from streamlit_ace import st_ace
 
 
 
 
9
  from agent import (
10
+ AppType,
11
+ createLlamaPrompt,
12
+ createSpace,
13
+ isPythonOrGradioAppPrompt,
14
+ isReactAppPrompt,
15
+ isStreamlitAppPrompt,
16
+ generateFiles,
17
  )
18
+
19
+ import importlib
20
+ import sys
21
+
22
+ def initialize_global_variables():
23
+ global HUGGING_FACE_REPO_URL, PROJECT_ROOT, AGENT_DIRECTORY
24
+ HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/Mistri"
25
+ PROJECT_ROOT = "projects"
26
+ AGENT_DIRECTORY = "agents"
27
+
28
+ initialize_global_variables()
29
+
30
+ # Initialize session state attributes
31
+ for attr in ['chat_history', 'terminal_history', 'workspace_projects', 'available_agents', 'current_state']:
32
+ if attr not in st.session_state:
33
+ st.session_state[attr] = []
34
+
35
+ def save_agent_to_file(agent):
36
+ agents_path = os.path.join(PROJECT_ROOT, AGENT_DIRECTORY)
37
+ if not os.path.exists(agents_path):
38
+ os.makedirs(agents_path)
39
+
40
+ agent_file = os.path.join(agents_path, f"{agent.name}.txt")
41
+ config_file = os.path.join(agents_path, f"{agent.name}Config.txt")
42
+
43
+ with open(agent_file, "w") as file:
44
+ file.write(agent.create_agent_prompt())
45
+
46
+ with open(config_file, "w") as file:
47
+ file.write(f"Agent Name: {agent.name}\nDescription: {agent.description}")
48
+
49
+ st.session_state.available_agents.append(agent.name)
50
+
51
+ commit_and_push_changes(f"Add agent {agent.name}")
52
+
53
+ def load_agent_prompt(agent_name):
54
+ agent_file = os.path.join(AGENT_DIRECTORY, f"{agent_name}.txt")
55
+ if os.path.exists(agent_file):
56
+ with open(agent_file, "r") as file:
57
+ agent_prompt = file.read()
58
+ return agent_prompt
59
+ else:
60
+ return None
61
+
62
+ def create_agent_from_text(name, text):
63
+ skills = text.split('\n')
64
+ agent = AIAgent(name, "AI agent created from text input.", skills)
65
+ save_agent_to_file(agent)
66
+ return agent.create_agent_prompt()
67
 
68
  # Global Variables
69
  terminal_history = ""