acecalisto3 commited on
Commit
378f793
1 Parent(s): 24fde8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -22
app.py CHANGED
@@ -46,17 +46,17 @@ def autonomous_build(self, chat_history, workspace_projects):
46
  """
47
  Autonomous build logic based on chat history and workspace projects.
48
  """
49
- summary = "Chat History:\n" + "\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])
50
- summary += "\n\nWorkspace Projects:\n" + '\n'.join([f"{p}: {', '.join(details.keys())}" for p, details in workspace_projects.items()])
51
 
52
  sentiment_analyzer = pipeline("sentiment-analysis")
53
  sentiment_output = sentiment_analyzer(summary)[0]
54
 
55
- # Use a Hugging Face model for more advanced logic (e.g., a summarization model)
56
  summarizer = pipeline("summarization")
57
  next_step = summarizer(summary, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
58
 
59
- return summary, next_step
60
 
61
  # Function to save an agent's prompt to a file and commit to the Hugging Face repository
62
  def save_agent_to_file(agent):
@@ -64,16 +64,16 @@ def save_agent_to_file(agent):
64
  agents_path = os.path.join(PROJECT_ROOT, AGENT_DIRECTORY)
65
  if not os.path.exists(agents_path):
66
  os.makedirs(agents_path)
67
-
68
  agent_file = os.path.join(agents_path, f"{agent.name}.txt")
69
  config_file = os.path.join(agents_path, f"{agent.name}Config.txt")
70
-
71
  with open(agent_file, "w") as file:
72
  file.write(agent.create_agent_prompt())
73
-
74
  with open(config_file, "w") as file:
75
  file.write(f"Agent Name: {agent.name}\nDescription: {agent.description}")
76
-
77
  st.session_state.available_agents.append(agent.name)
78
 
79
  commit_and_push_changes(f"Add agent {agent.name}")
@@ -130,7 +130,7 @@ def workspace_interface(project_name):
130
  if not os.path.exists(PROJECT_ROOT):
131
  os.makedirs(PROJECT_ROOT)
132
  if not os.path.exists(project_path):
133
- os topscorer.session_state.workspace_projects[project_name] = {"files": []}
134
  st.session_state.current_state['workspace_chat']['project_name'] = project_name
135
  commit_and_push_changes(f"Create project {project_name}")
136
  return f"Project {project_name} created successfully."
@@ -166,7 +166,7 @@ def terminal_interface(command, project_name=None):
166
  else:
167
  st.session_state.current_state['toolbox']['terminal_output'] = result.stderr
168
  return result.stderr
169
-
170
  # Code editor interface for formatting and linting
171
  def code_editor_interface(code):
172
  try:
@@ -176,7 +176,7 @@ def code_editor_interface(code):
176
  result = StringIO()
177
  sys.stdout = result
178
  sys.stderr = result
179
- (pylint_stdout, pylint_stderr) = lint.py_run(code, return_std=True)
180
  sys.stdout = sys.stdout
181
  sys.stderr = sys.stderr
182
  lint_message = pylint_stdout.getvalue() + pylint_stderr.getvalue()
@@ -202,7 +202,7 @@ def sentiment_analysis(text):
202
  def translate_code(code, input_language, output_language):
203
  # Define a dictionary to map programming languages to their corresponding file extensions
204
  language_extensions = {
205
- # ignore the specific languages right now, and continue to EOF
206
  }
207
 
208
  # Add code to handle edge cases such as invalid input and unsupported programming languages
@@ -227,7 +227,6 @@ def translate_code(code, input_language, output_language):
227
  translated_code = response.choices[0].message['content'].strip()
228
 
229
  # Return the translated code
230
- translated_code = response.choices[0].message['content'].strip()
231
  st.session_state.current_state['toolbox']['translated_code'] = translated_code
232
  return translated_code
233
 
@@ -286,8 +285,8 @@ elif app_mode == "Tool Box":
286
  chat_input = st.text_area("Enter your message:")
287
  if st.button("Send"):
288
  if chat_input.startswith("@"):
289
- agent_name = chat_input.split(" ")[0][1:] # Extract agent_name from @agent_name
290
- chat_input = " ".join(chat_input.split(" ")[1:]) # Remove agent_name from input
291
  chat_response = chat_interface_with_agent(chat_input, agent_name)
292
  else:
293
  chat_response = chat_interface(chat_input)
@@ -330,8 +329,7 @@ elif app_mode == "Tool Box":
330
  source_language = st.text_input("Enter source language (e.g. 'Python'):")
331
  target_language = st.text_input("Enter target language (e.g. 'JavaScript'):")
332
  if st.button("Translate Code"):
333
- # Use a Hugging Face translation model
334
- translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
335
  translated_code = translator(code_to_translate, target_lang=target_language)[0]['translation_text']
336
  st.code(translated_code, language=target_language.lower())
337
 
@@ -339,8 +337,7 @@ elif app_mode == "Tool Box":
339
  st.subheader("Code Generation")
340
  code_idea = st.text_input("Enter your code idea:")
341
  if st.button("Generate Code"):
342
- # Use a Hugging Face code generation model
343
- generator = pipeline("text-generation", model="bigscience/T0_3B")
344
  generated_code = generator(code_idea, max_length=100, num_return_sequences=1, do_sample=True)[0]['generated_text']
345
  st.code(generated_code, language="python")
346
 
@@ -357,7 +354,7 @@ elif app_mode == "Tool Box":
357
  }
358
  for command_name, command in preset_commands.items():
359
  st.write(f"{command_name}: `{command}`")
360
-
361
  # Workspace Chat App
362
  elif app_mode == "Workspace Chat App":
363
  st.header("Workspace Chat App")
@@ -434,5 +431,5 @@ elif app_mode == "Workspace Chat App":
434
  st.sidebar.subheader("Current State")
435
  st.sidebar.json(st.session_state.current_state)
436
 
437
- if __name__ == "__main__":
438
- os.system("streamlit run app.py")
 
46
  """
47
  Autonomous build logic based on chat history and workspace projects.
48
  """
49
+ summary = "Chat History:\n" + '\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])
50
+ summary += "\n\nWorkspace Projects:\n" + '\n'.join([f"{p}: {', '.join(ws_projects.keys())}" for p, ws_projects in workspace_projects.items()])
51
 
52
  sentiment_analyzer = pipeline("sentiment-analysis")
53
  sentiment_output = sentiment_analyzer(summary)[0]
54
 
55
+ # Use a Hugging Face model for more advanced logic
56
  summarizer = pipeline("summarization")
57
  next_step = summarizer(summary, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
58
 
59
+ return summary, next_step
60
 
61
  # Function to save an agent's prompt to a file and commit to the Hugging Face repository
62
  def save_agent_to_file(agent):
 
64
  agents_path = os.path.join(PROJECT_ROOT, AGENT_DIRECTORY)
65
  if not os.path.exists(agents_path):
66
  os.makedirs(agents_path)
67
+
68
  agent_file = os.path.join(agents_path, f"{agent.name}.txt")
69
  config_file = os.path.join(agents_path, f"{agent.name}Config.txt")
70
+
71
  with open(agent_file, "w") as file:
72
  file.write(agent.create_agent_prompt())
73
+
74
  with open(config_file, "w") as file:
75
  file.write(f"Agent Name: {agent.name}\nDescription: {agent.description}")
76
+
77
  st.session_state.available_agents.append(agent.name)
78
 
79
  commit_and_push_changes(f"Add agent {agent.name}")
 
130
  if not os.path.exists(PROJECT_ROOT):
131
  os.makedirs(PROJECT_ROOT)
132
  if not os.path.exists(project_path):
133
+ st.session_state.workspace_projects[project_name] = {"files": []}
134
  st.session_state.current_state['workspace_chat']['project_name'] = project_name
135
  commit_and_push_changes(f"Create project {project_name}")
136
  return f"Project {project_name} created successfully."
 
166
  else:
167
  st.session_state.current_state['toolbox']['terminal_output'] = result.stderr
168
  return result.stderr
169
+
170
  # Code editor interface for formatting and linting
171
  def code_editor_interface(code):
172
  try:
 
176
  result = StringIO()
177
  sys.stdout = result
178
  sys.stderr = result
179
+ pylint_stdout, pylint_stderr = lint.py_run(code, return_std=True)
180
  sys.stdout = sys.stdout
181
  sys.stderr = sys.stderr
182
  lint_message = pylint_stdout.getvalue() + pylint_stderr.getvalue()
 
202
  def translate_code(code, input_language, output_language):
203
  # Define a dictionary to map programming languages to their corresponding file extensions
204
  language_extensions = {
205
+ # Add language extensions here
206
  }
207
 
208
  # Add code to handle edge cases such as invalid input and unsupported programming languages
 
227
  translated_code = response.choices[0].message['content'].strip()
228
 
229
  # Return the translated code
 
230
  st.session_state.current_state['toolbox']['translated_code'] = translated_code
231
  return translated_code
232
 
 
285
  chat_input = st.text_area("Enter your message:")
286
  if st.button("Send"):
287
  if chat_input.startswith("@"):
288
+ agent_name = chat_input.split(" ")[0][1:]
289
+ chat_input = " ".join(chat_input.split(" ")[1:])
290
  chat_response = chat_interface_with_agent(chat_input, agent_name)
291
  else:
292
  chat_response = chat_interface(chat_input)
 
329
  source_language = st.text_input("Enter source language (e.g. 'Python'):")
330
  target_language = st.text_input("Enter target language (e.g. 'JavaScript'):")
331
  if st.button("Translate Code"):
332
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
 
333
  translated_code = translator(code_to_translate, target_lang=target_language)[0]['translation_text']
334
  st.code(translated_code, language=target_language.lower())
335
 
 
337
  st.subheader("Code Generation")
338
  code_idea = st.text_input("Enter your code idea:")
339
  if st.button("Generate Code"):
340
+ generator = pipeline("text-generation", model="bigscience/T0_3B")
 
341
  generated_code = generator(code_idea, max_length=100, num_return_sequences=1, do_sample=True)[0]['generated_text']
342
  st.code(generated_code, language="python")
343
 
 
354
  }
355
  for command_name, command in preset_commands.items():
356
  st.write(f"{command_name}: `{command}`")
357
+
358
  # Workspace Chat App
359
  elif app_mode == "Workspace Chat App":
360
  st.header("Workspace Chat App")
 
431
  st.sidebar.subheader("Current State")
432
  st.sidebar.json(st.session_state.current_state)
433
 
434
+ if __name__ == "__main__":
435
+ os.system("streamlit run app.py")