acecalisto3 commited on
Commit
e3abd51
·
verified ·
1 Parent(s): d784a5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -1,10 +1,18 @@
1
  import os
2
  import subprocess
3
- import sys # Add sys import
4
  import streamlit as st
5
  import black
6
  from pylint import lint
7
  from io import StringIO
 
 
 
 
 
 
 
 
8
 
9
  HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"
10
  PROJECT_ROOT = "projects"
@@ -36,24 +44,17 @@ class AIAgent:
36
  agent_prompt = f"""
37
  As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:
38
  {skills_str}
39
-
40
  I am confident that I can leverage my expertise to assist you in developing and deploying cutting-edge web applications. Please feel free to ask any questions or present any challenges you may encounter.
41
  """
42
  return agent_prompt
43
 
44
  def autonomous_build(self, chat_history, workspace_projects):
45
- """
46
- Autonomous build logic that continues based on the state of chat history and workspace projects.
47
- """
48
- summary = "Chat History:\n" + "\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])
49
  summary += "\n\nWorkspace Projects:\n" + "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
50
-
51
  next_step = "Based on the current state, the next logical step is to implement the main application logic."
52
-
53
  return summary, next_step
54
 
55
  def save_agent_to_file(agent):
56
- """Saves the agent's prompt to a file locally and then commits to the Hugging Face repository."""
57
  if not os.path.exists(AGENT_DIRECTORY):
58
  os.makedirs(AGENT_DIRECTORY)
59
  file_path = os.path.join(AGENT_DIRECTORY, f"{agent.name}.txt")
@@ -66,7 +67,6 @@ def save_agent_to_file(agent):
66
  commit_and_push_changes(f"Add agent {agent.name}")
67
 
68
  def load_agent_prompt(agent_name):
69
- """Loads an agent prompt from a file."""
70
  file_path = os.path.join(AGENT_DIRECTORY, f"{agent_name}.txt")
71
  if os.path.exists(file_path):
72
  with open(file_path, "r") as file:
@@ -84,8 +84,8 @@ def create_agent_from_text(name, text):
84
  def chat_interface(input_text):
85
  """Handles chat interactions without a specific agent."""
86
  try:
87
- model = InstructModel()
88
- response = model.generate_response(f"User: {input_text}\nAI:")
89
  return response
90
  except EnvironmentError as e:
91
  return f"Error communicating with AI: {e}"
@@ -100,8 +100,8 @@ def chat_interface_with_agent(input_text, agent_name):
100
  except EnvironmentError as e:
101
  return f"Error loading model: {e}"
102
 
103
- combined_input = f"{agent_prompt}\n\nUser: {input_text}\nAgent:"
104
- response = model.generate_response(combined_input) # Generate response using Mixtral Instruct
105
  return response
106
 
107
  def workspace_interface(project_name):
@@ -174,8 +174,9 @@ def translate_code(code, input_language, output_language):
174
  return translated_code
175
  except EnvironmentError as e:
176
  return f"Error loading model or translating code: {e}"
177
- except Exception as e: # Catch other potential errors during translation.
178
  return f"An unexpected error occurred during code translation: {e}"
 
179
  def generate_code(code_idea):
180
  try:
181
  model = InstructModel() # Initialize Mixtral Instruct model
@@ -190,7 +191,6 @@ def generate_code(code_idea):
190
  def commit_and_push_changes(commit_message):
191
  """Commits and pushes changes to the Hugging Face repository (needs improvement)."""
192
  try:
193
- # Add error checking for git repository existence.
194
  subprocess.run(["git", "add", "."], check=True, capture_output=True, text=True)
195
  subprocess.run(["git", "commit", "-m", commit_message], check=True, capture_output=True, text=True)
196
  subprocess.run(["git", "push"], check=True, capture_output=True, text=True)
@@ -207,6 +207,7 @@ st.sidebar.title("Navigation")
207
  app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
208
 
209
  if app_mode == "AI Agent Creator":
 
210
  # AI Agent Creator
211
  st.header("Create an AI Agent from Text")
212
 
@@ -304,7 +305,7 @@ elif app_mode == "Workspace Chat App":
304
  # Display Chat History
305
  st.subheader("Chat History")
306
  for user_input, response in st.session_state.chat_history:
307
- st.write(f"User: {user_input}")
308
  st.write(f"CodeCraft: {response}")
309
 
310
  # Display Terminal History
@@ -316,7 +317,7 @@ elif app_mode == "Workspace Chat App":
316
  # Display Projects and Files
317
  st.subheader("Workspace Projects")
318
  for project, details in st.session_state.workspace_projects.items():
319
- st.write(f"Project: {project}")
320
  for file in details['files']:
321
  st.write(f" - {file}")
322
 
 
1
  import os
2
  import subprocess
3
+ import sys
4
  import streamlit as st
5
  import black
6
  from pylint import lint
7
  from io import StringIO
8
+ import requests
9
+ import logging
10
+ import atexit
11
+ import time
12
+ from datetime import datetime
13
+
14
+ # Import the InstructModel from the appropriate library
15
+ from mistralai import InstructModel # Ensure you have the correct import for the model
16
 
17
  HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"
18
  PROJECT_ROOT = "projects"
 
44
  agent_prompt = f"""
45
  As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:
46
  {skills_str}
 
47
  I am confident that I can leverage my expertise to assist you in developing and deploying cutting-edge web applications. Please feel free to ask any questions or present any challenges you may encounter.
48
  """
49
  return agent_prompt
50
 
51
  def autonomous_build(self, chat_history, workspace_projects):
52
+ summary = "Chat History:\n" + "\n".join([f":User {u}\nAgent: {a}" for u, a in chat_history])
 
 
 
53
  summary += "\n\nWorkspace Projects:\n" + "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
 
54
  next_step = "Based on the current state, the next logical step is to implement the main application logic."
 
55
  return summary, next_step
56
 
57
  def save_agent_to_file(agent):
 
58
  if not os.path.exists(AGENT_DIRECTORY):
59
  os.makedirs(AGENT_DIRECTORY)
60
  file_path = os.path.join(AGENT_DIRECTORY, f"{agent.name}.txt")
 
67
  commit_and_push_changes(f"Add agent {agent.name}")
68
 
69
  def load_agent_prompt(agent_name):
 
70
  file_path = os.path.join(AGENT_DIRECTORY, f"{agent_name}.txt")
71
  if os.path.exists(file_path):
72
  with open(file_path, "r") as file:
 
84
  def chat_interface(input_text):
85
  """Handles chat interactions without a specific agent."""
86
  try:
87
+ model = InstructModel() # Initialize the Mixtral Instruct model
88
+ response = model.generate_response(f":User {input_text}\nAI:")
89
  return response
90
  except EnvironmentError as e:
91
  return f"Error communicating with AI: {e}"
 
100
  except EnvironmentError as e:
101
  return f"Error loading model: {e}"
102
 
103
+ combined_input = f"{agent_prompt}\n\n:User {input_text}\nAgent:"
104
+ response = model.generate_response(combined_input) ```python
105
  return response
106
 
107
  def workspace_interface(project_name):
 
174
  return translated_code
175
  except EnvironmentError as e:
176
  return f"Error loading model or translating code: {e}"
177
+ except Exception as e:
178
  return f"An unexpected error occurred during code translation: {e}"
179
+
180
  def generate_code(code_idea):
181
  try:
182
  model = InstructModel() # Initialize Mixtral Instruct model
 
191
  def commit_and_push_changes(commit_message):
192
  """Commits and pushes changes to the Hugging Face repository (needs improvement)."""
193
  try:
 
194
  subprocess.run(["git", "add", "."], check=True, capture_output=True, text=True)
195
  subprocess.run(["git", "commit", "-m", commit_message], check=True, capture_output=True, text=True)
196
  subprocess.run(["git", "push"], check=True, capture_output=True, text=True)
 
207
  app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
208
 
209
  if app_mode == "AI Agent Creator":
210
+ ```python
211
  # AI Agent Creator
212
  st.header("Create an AI Agent from Text")
213
 
 
305
  # Display Chat History
306
  st.subheader("Chat History")
307
  for user_input, response in st.session_state.chat_history:
308
+ st.write(f":User {user_input}")
309
  st.write(f"CodeCraft: {response}")
310
 
311
  # Display Terminal History
 
317
  # Display Projects and Files
318
  st.subheader("Workspace Projects")
319
  for project, details in st.session_state.workspace_projects.items():
320
+ st.write(f"Project: {project }")
321
  for file in details['files']:
322
  st.write(f" - {file}")
323