Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,13 @@
|
|
1 |
-
import os
|
2 |
import subprocess
|
3 |
import streamlit as st
|
4 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
5 |
import black
|
6 |
from pylint import lint
|
7 |
from io import StringIO
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Set Hugging Face repository URL and project root path
|
10 |
HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/Mistri"
|
@@ -42,21 +45,18 @@ I am confident that I can leverage my expertise to assist you in developing and
|
|
42 |
"""
|
43 |
return agent_prompt
|
44 |
|
45 |
-
def autonomous_build(self, chat_history, workspace_projects):
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
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):
|
@@ -202,7 +202,11 @@ 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 |
-
|
|
|
|
|
|
|
|
|
206 |
}
|
207 |
|
208 |
# Add code to handle edge cases such as invalid input and unsupported programming languages
|
@@ -329,16 +333,14 @@ elif app_mode == "Tool Box":
|
|
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 |
-
|
333 |
-
translated_code = translator(code_to_translate, target_lang=target_language)[0]['translation_text']
|
334 |
st.code(translated_code, language=target_language.lower())
|
335 |
|
336 |
# Code Generation
|
337 |
st.subheader("Code Generation")
|
338 |
code_idea = st.text_input("Enter your code idea:")
|
339 |
if st.button("Generate Code"):
|
340 |
-
|
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 |
|
344 |
# Display Preset Commands
|
@@ -427,6 +429,28 @@ elif app_mode == "Workspace Chat App":
|
|
427 |
st.write("Next Step:")
|
428 |
st.write(next_step)
|
429 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
# Display current state for debugging
|
431 |
st.sidebar.subheader("Current State")
|
432 |
st.sidebar.json(st.session_state.current_state)
|
|
|
|
|
1 |
import subprocess
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
4 |
import black
|
5 |
from pylint import lint
|
6 |
from io import StringIO
|
7 |
+
import os
|
8 |
+
import openai
|
9 |
+
import json
|
10 |
+
from streamlit_ace import st_ace
|
11 |
|
12 |
# Set Hugging Face repository URL and project root path
|
13 |
HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/Mistri"
|
|
|
45 |
"""
|
46 |
return agent_prompt
|
47 |
|
48 |
+
def autonomous_build(self, chat_history, workspace_projects):
|
49 |
+
"""
|
50 |
+
Autonomous build logic based on chat history and workspace projects.
|
51 |
+
"""
|
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}: {', '.join(ws_projects.keys())}" for p, ws_projects in workspace_projects.items()])
|
54 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
55 |
+
sentiment_output = sentiment_analyzer(summary)[0]
|
56 |
+
# Use a Hugging Face model for more advanced logic
|
57 |
+
summarizer = pipeline("summarization")
|
58 |
+
next_step = summarizer(summary, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
|
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):
|
|
|
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 |
+
"Python": ".py",
|
206 |
+
"JavaScript": ".js",
|
207 |
+
"C++": ".cpp",
|
208 |
+
"Java": ".java",
|
209 |
+
# Add more languages and extensions as needed
|
210 |
}
|
211 |
|
212 |
# Add code to handle edge cases such as invalid input and unsupported programming languages
|
|
|
333 |
source_language = st.text_input("Enter source language (e.g. 'Python'):")
|
334 |
target_language = st.text_input("Enter target language (e.g. 'JavaScript'):")
|
335 |
if st.button("Translate Code"):
|
336 |
+
translated_code = translate_code(code_to_translate, source_language, target_language)
|
|
|
337 |
st.code(translated_code, language=target_language.lower())
|
338 |
|
339 |
# Code Generation
|
340 |
st.subheader("Code Generation")
|
341 |
code_idea = st.text_input("Enter your code idea:")
|
342 |
if st.button("Generate Code"):
|
343 |
+
generated_code = generate_code(code_idea)
|
|
|
344 |
st.code(generated_code, language="python")
|
345 |
|
346 |
# Display Preset Commands
|
|
|
429 |
st.write("Next Step:")
|
430 |
st.write(next_step)
|
431 |
|
432 |
+
# Advanced Code Editor (Optional)
|
433 |
+
st.subheader("Advanced Code Editor")
|
434 |
+
selected_file = st.selectbox("Select a file from the workspace", st.session_state.workspace_projects[project_name]['files'])
|
435 |
+
file_path = os.path.join(PROJECT_ROOT, project_name, selected_file)
|
436 |
+
if os.path.exists(file_path):
|
437 |
+
with open(file_path, "r") as file:
|
438 |
+
file_content = file.read()
|
439 |
+
code_editor = st_ace(
|
440 |
+
file_content,
|
441 |
+
language="python",
|
442 |
+
theme="monokai",
|
443 |
+
height=300,
|
444 |
+
key="ace_editor",
|
445 |
+
)
|
446 |
+
if st.button("Save Changes"):
|
447 |
+
with open(file_path, "w") as file:
|
448 |
+
file.write(code_editor)
|
449 |
+
st.success(f"Changes saved to {selected_file}")
|
450 |
+
commit_and_push_changes(f"Update {selected_file}")
|
451 |
+
else:
|
452 |
+
st.warning(f"File {selected_file} not found in the workspace.")
|
453 |
+
|
454 |
# Display current state for debugging
|
455 |
st.sidebar.subheader("Current State")
|
456 |
st.sidebar.json(st.session_state.current_state)
|