Spaces:
Sleeping
Sleeping
acecalisto3
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
|
5 |
from huggingface_hub import HfApi
|
6 |
|
7 |
# Set your Hugging Face API key here
|
8 |
-
huggingface_token = "
|
9 |
|
10 |
PROJECT_ROOT = "projects"
|
11 |
AGENT_DIRECTORY = "agents"
|
@@ -21,6 +21,9 @@ if 'workspace_projects' not in st.session_state:
|
|
21 |
if 'available_agents' not in st.session_state:
|
22 |
st.session_state.available_agents = []
|
23 |
|
|
|
|
|
|
|
24 |
class AIAgent:
|
25 |
def __init__(self, name, description, skills):
|
26 |
self.name = name
|
@@ -38,20 +41,12 @@ I am confident that I can leverage my expertise to assist you in developing and
|
|
38 |
return agent_prompt
|
39 |
|
40 |
def autonomous_build(self, chat_history, workspace_projects, project_name, selected_model, hf_token):
|
41 |
-
"""
|
42 |
-
Autonomous build logic that continues based on the state of chat history and workspace projects.
|
43 |
-
"""
|
44 |
-
# Example logic: Generate a summary of chat history and workspace state
|
45 |
summary = "Chat History:\n" + "\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])
|
46 |
summary += "\n\nWorkspace Projects:\n" + "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
|
47 |
-
|
48 |
-
# Example: Generate the next logical step in the project
|
49 |
next_step = "Based on the current state, the next logical step is to implement the main application logic."
|
50 |
-
|
51 |
return summary, next_step
|
52 |
|
53 |
def deploy_built_space_to_hf(self):
|
54 |
-
# Implement deployment logic here
|
55 |
pass
|
56 |
|
57 |
def process_input(input_text):
|
@@ -94,236 +89,209 @@ def display_workspace_projects(workspace_projects):
|
|
94 |
|
95 |
if __name__ == "__main__":
|
96 |
st.sidebar.title("Navigation")
|
97 |
-
app_mode = st.sidebar.selectbox("Choose the app mode", ["
|
98 |
-
|
99 |
-
if app_mode == "
|
100 |
-
|
101 |
-
st.
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
if st.button("Create Agent"):
|
107 |
-
skills = text_input.split('\n')
|
108 |
-
agent = AIAgent(agent_name, "AI agent created from text input", skills)
|
109 |
-
st.success(f"Agent '{agent_name}' created and saved successfully.")
|
110 |
-
st.session_state.available_agents.append(agent_name)
|
111 |
-
|
112 |
-
elif app_mode == "Tool Box":
|
113 |
-
# Tool Box
|
114 |
-
st.header("AI-Powered Tools")
|
115 |
-
|
116 |
-
# Chat Interface
|
117 |
-
st.subheader("Chat with CodeCraft")
|
118 |
-
chat_input = st.text_area("Enter your message:")
|
119 |
-
if st.button("Send"):
|
120 |
-
response = process_input(chat_input)
|
121 |
-
st.session_state.chat_history.append((chat_input, response))
|
122 |
-
st.write(f"CodeCraft: {response}")
|
123 |
-
|
124 |
-
# Terminal Interface
|
125 |
-
st.subheader("Terminal")
|
126 |
terminal_input = st.text_input("Enter a command:")
|
127 |
if st.button("Run"):
|
128 |
output = run_code(terminal_input)
|
129 |
st.session_state.terminal_history.append((terminal_input, output))
|
130 |
st.code(output, language="bash")
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
st.
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
st.
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
st.write(
|
167 |
-
|
168 |
-
|
169 |
-
st.
|
170 |
-
|
171 |
-
selected_model = st.selectbox("Select a code-generative model", AVAILABLE_CODE_GENERATIVE_MODELS)
|
172 |
-
if st.button("Generate Code"):
|
173 |
-
generator = pipeline("text-generation", model=selected_model, tokenizer=selected_model)
|
174 |
-
generated_code = generator(code_idea, max_length=150, num_return_sequences=1)[0]['generated_text']
|
175 |
-
st.code(generated_code, language="python")
|
176 |
-
|
177 |
-
# Automate Build Process
|
178 |
-
st.subheader("Automate Build Process")
|
179 |
if st.button("Automate"):
|
|
|
|
|
180 |
agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
|
181 |
-
summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects, project_name_input, selected_model,
|
182 |
st.write("Autonomous Build Summary:")
|
183 |
st.write(summary)
|
184 |
st.write("Next Step:")
|
185 |
st.write(next_step)
|
186 |
-
|
187 |
if agent._hf_api and agent.has_valid_hf_token():
|
188 |
repository = agent.deploy_built_space_to_hf()
|
189 |
st.markdown("## Congratulations! Successfully deployed Space 🚀 ##")
|
190 |
st.markdown("[Check out your new Space here](hf.co/" + repository.name + ")")
|
191 |
|
192 |
-
#
|
193 |
-
st.markdown("""
|
194 |
-
<style>
|
195 |
-
/* Advanced and Accommodating CSS */
|
196 |
-
body {
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
}
|
203 |
-
|
204 |
-
h1, h2, h3, h4, h5, h6 {
|
205 |
-
|
206 |
-
}
|
207 |
-
|
208 |
-
.container {
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
}
|
213 |
-
|
214 |
-
/* Navigation Sidebar */
|
215 |
-
.sidebar {
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
}
|
226 |
-
|
227 |
-
.sidebar a {
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
}
|
233 |
-
|
234 |
-
.sidebar a:hover {
|
235 |
-
|
236 |
-
|
237 |
-
}
|
238 |
-
|
239 |
-
/* Main Content */
|
240 |
-
.main-content {
|
241 |
-
|
242 |
-
|
243 |
-
}
|
244 |
-
|
245 |
-
/* Buttons */
|
246 |
-
button {
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
}
|
255 |
-
|
256 |
-
button:hover {
|
257 |
-
|
258 |
-
}
|
259 |
-
|
260 |
-
/* Text Areas and Inputs */
|
261 |
-
textarea, input[type="text"] {
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
}
|
269 |
-
|
270 |
-
textarea:focus, input[type="text"]:focus {
|
271 |
-
|
272 |
-
|
273 |
-
}
|
274 |
-
|
275 |
-
/* Terminal Output */
|
276 |
-
.code-output {
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
}
|
283 |
-
|
284 |
-
/* Chat History */
|
285 |
-
.chat-history {
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
}
|
292 |
-
|
293 |
-
.chat-message {
|
294 |
-
|
295 |
-
}
|
296 |
-
|
297 |
-
.chat-message.user {
|
298 |
-
|
299 |
-
|
300 |
-
}
|
301 |
-
|
302 |
-
.chat-message.agent {
|
303 |
-
|
304 |
-
|
305 |
-
}
|
306 |
-
|
307 |
-
/* Project Management */
|
308 |
-
.project-list {
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
}
|
315 |
-
|
316 |
-
.project-item {
|
317 |
-
|
318 |
-
}
|
319 |
-
|
320 |
-
.project-item a {
|
321 |
-
|
322 |
-
|
323 |
-
}
|
324 |
-
|
325 |
-
.project-item a:hover {
|
326 |
-
|
327 |
-
}
|
328 |
-
</style>
|
329 |
-
""", unsafe_allow_html=True)
|
|
|
5 |
from huggingface_hub import HfApi
|
6 |
|
7 |
# Set your Hugging Face API key here
|
8 |
+
huggingface_token = st.secrets["huggingface"]["hf_token"]
|
9 |
|
10 |
PROJECT_ROOT = "projects"
|
11 |
AGENT_DIRECTORY = "agents"
|
|
|
21 |
if 'available_agents' not in st.session_state:
|
22 |
st.session_state.available_agents = []
|
23 |
|
24 |
+
# AI Guide Toggle
|
25 |
+
ai_guide_level = st.sidebar.radio("AI Guide Level", ["Full Assistance", "Partial Assistance", "No Assistance"])
|
26 |
+
|
27 |
class AIAgent:
|
28 |
def __init__(self, name, description, skills):
|
29 |
self.name = name
|
|
|
41 |
return agent_prompt
|
42 |
|
43 |
def autonomous_build(self, chat_history, workspace_projects, project_name, selected_model, hf_token):
|
|
|
|
|
|
|
|
|
44 |
summary = "Chat History:\n" + "\n".join([f"User: {u}\nAgent: {a}" for u, a in chat_history])
|
45 |
summary += "\n\nWorkspace Projects:\n" + "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
|
|
|
|
|
46 |
next_step = "Based on the current state, the next logical step is to implement the main application logic."
|
|
|
47 |
return summary, next_step
|
48 |
|
49 |
def deploy_built_space_to_hf(self):
|
|
|
50 |
pass
|
51 |
|
52 |
def process_input(input_text):
|
|
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
st.sidebar.title("Navigation")
|
92 |
+
app_mode = st.sidebar.selectbox("Choose the app mode", ["Home", "Terminal", "Explorer", "Code Editor", "Build & Deploy"])
|
93 |
+
|
94 |
+
if app_mode == "Home":
|
95 |
+
st.title("Welcome to AI-Guided Development")
|
96 |
+
st.write("This application helps you build and deploy applications with the assistance of an AI Guide.")
|
97 |
+
st.write("Toggle the AI Guide from the sidebar to choose the level of assistance you need.")
|
98 |
+
|
99 |
+
elif app_mode == "Terminal":
|
100 |
+
st.header("Terminal")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
terminal_input = st.text_input("Enter a command:")
|
102 |
if st.button("Run"):
|
103 |
output = run_code(terminal_input)
|
104 |
st.session_state.terminal_history.append((terminal_input, output))
|
105 |
st.code(output, language="bash")
|
106 |
+
if ai_guide_level != "No Assistance":
|
107 |
+
st.write("Run commands here to add packages to your project. For example: `pip install <package-name>`.")
|
108 |
+
if terminal_input and "install" in terminal_input:
|
109 |
+
package_name = terminal_input.split("install")[-1].strip()
|
110 |
+
st.write(f"Package `{package_name}` will be added to your project.")
|
111 |
+
|
112 |
+
elif app_mode == "Explorer":
|
113 |
+
st.header("Explorer")
|
114 |
+
uploaded_file = st.file_uploader("Upload a file", type=["py"])
|
115 |
+
if uploaded_file:
|
116 |
+
file_details = {"FileName": uploaded_file.name, "FileType": uploaded_file.type}
|
117 |
+
st.write(file_details)
|
118 |
+
save_path = os.path.join(PROJECT_ROOT, uploaded_file.name)
|
119 |
+
with open(save_path, "wb") as f:
|
120 |
+
f.write(uploaded_file.getbuffer())
|
121 |
+
st.success(f"File {uploaded_file.name} saved successfully!")
|
122 |
+
|
123 |
+
st.write("Drag and drop files into the 'app' folder.")
|
124 |
+
for project, details in st.session_state.workspace_projects.items():
|
125 |
+
st.write(f"Project: {project}")
|
126 |
+
for file in details['files']:
|
127 |
+
st.write(f" - {file}")
|
128 |
+
if st.button(f"Move {file} to app folder"):
|
129 |
+
# Logic to move file to 'app' folder
|
130 |
+
pass
|
131 |
+
if ai_guide_level != "No Assistance":
|
132 |
+
st.write("You can upload files and move them into the 'app' folder for building your application.")
|
133 |
+
|
134 |
+
elif app_mode == "Code Editor":
|
135 |
+
st.header("Code Editor")
|
136 |
+
code_editor = st.text_area("Write your code:", height=300)
|
137 |
+
if st.button("Save Code"):
|
138 |
+
# Logic to save code
|
139 |
+
pass
|
140 |
+
if ai_guide_level != "No Assistance":
|
141 |
+
st.write("The function `foo()` requires the `bar` package. Add it to `requirements.txt`.")
|
142 |
+
|
143 |
+
elif app_mode == "Build & Deploy":
|
144 |
+
st.header("Build & Deploy")
|
145 |
+
project_name_input = st.text_input("Enter Project Name for Automation:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
if st.button("Automate"):
|
147 |
+
selected_agent = st.selectbox("Select an AI agent", st.session_state.available_agents)
|
148 |
+
selected_model = st.selectbox("Select a code-generative model", AVAILABLE_CODE_GENERATIVE_MODELS)
|
149 |
agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
|
150 |
+
summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects, project_name_input, selected_model, huggingface_token)
|
151 |
st.write("Autonomous Build Summary:")
|
152 |
st.write(summary)
|
153 |
st.write("Next Step:")
|
154 |
st.write(next_step)
|
|
|
155 |
if agent._hf_api and agent.has_valid_hf_token():
|
156 |
repository = agent.deploy_built_space_to_hf()
|
157 |
st.markdown("## Congratulations! Successfully deployed Space 🚀 ##")
|
158 |
st.markdown("[Check out your new Space here](hf.co/" + repository.name + ")")
|
159 |
|
160 |
+
# CSS for styling
|
161 |
+
st.markdown("""
|
162 |
+
<style>
|
163 |
+
/* Advanced and Accommodating CSS */
|
164 |
+
body {
|
165 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
166 |
+
background-color: #f4f4f9;
|
167 |
+
color: #333;
|
168 |
+
margin: 0;
|
169 |
+
padding: 0;
|
170 |
+
}
|
171 |
+
|
172 |
+
h1, h2, h3, h4, h5, h6 {
|
173 |
+
color: #333;
|
174 |
+
}
|
175 |
+
|
176 |
+
.container {
|
177 |
+
width: 90%;
|
178 |
+
margin: 0 auto;
|
179 |
+
padding: 20px;
|
180 |
+
}
|
181 |
+
|
182 |
+
/* Navigation Sidebar */
|
183 |
+
.sidebar {
|
184 |
+
background-color: #2c3e50;
|
185 |
+
color: #ecf0f1;
|
186 |
+
padding: 20px;
|
187 |
+
height: 100vh;
|
188 |
+
position: fixed;
|
189 |
+
top: 0;
|
190 |
+
left: 0;
|
191 |
+
width: 250px;
|
192 |
+
overflow-y: auto;
|
193 |
+
}
|
194 |
+
|
195 |
+
.sidebar a {
|
196 |
+
color: #ecf0f1;
|
197 |
+
text-decoration: none;
|
198 |
+
display: block;
|
199 |
+
padding: 10px 0;
|
200 |
+
}
|
201 |
+
|
202 |
+
.sidebar a:hover {
|
203 |
+
background-color: #34495e;
|
204 |
+
border-radius: 5px;
|
205 |
+
}
|
206 |
+
|
207 |
+
/* Main Content */
|
208 |
+
.main-content {
|
209 |
+
margin-left: 270px;
|
210 |
+
padding: 20px;
|
211 |
+
}
|
212 |
+
|
213 |
+
/* Buttons */
|
214 |
+
button {
|
215 |
+
background-color: #3498db;
|
216 |
+
color: #fff;
|
217 |
+
border: none;
|
218 |
+
padding: 10px 20px;
|
219 |
+
border-radius: 5px;
|
220 |
+
cursor: pointer;
|
221 |
+
font-size: 16px;
|
222 |
+
}
|
223 |
+
|
224 |
+
button:hover {
|
225 |
+
background-color: #2980b9;
|
226 |
+
}
|
227 |
+
|
228 |
+
/* Text Areas and Inputs */
|
229 |
+
textarea, input[type="text"] {
|
230 |
+
width: 100%;
|
231 |
+
padding: 10px;
|
232 |
+
margin: 10px 0;
|
233 |
+
border: 1px solid #ddd;
|
234 |
+
border-radius: 5px;
|
235 |
+
box-sizing: border-box;
|
236 |
+
}
|
237 |
+
|
238 |
+
textarea:focus, input[type="text"]:focus {
|
239 |
+
border-color: #3498db;
|
240 |
+
outline: none;
|
241 |
+
}
|
242 |
+
|
243 |
+
/* Terminal Output */
|
244 |
+
.code-output {
|
245 |
+
background-color: #1e1e1e;
|
246 |
+
color: #dcdcdc;
|
247 |
+
padding: 20px;
|
248 |
+
border-radius: 5px;
|
249 |
+
font-family: 'Courier New', Courier, monospace;
|
250 |
+
}
|
251 |
+
|
252 |
+
/* Chat History */
|
253 |
+
.chat-history {
|
254 |
+
background-color: #ecf0f1;
|
255 |
+
padding: 20px;
|
256 |
+
border-radius: 5px;
|
257 |
+
max-height: 300px;
|
258 |
+
overflow-y: auto;
|
259 |
+
}
|
260 |
+
|
261 |
+
.chat-message {
|
262 |
+
margin-bottom: 10px;
|
263 |
+
}
|
264 |
+
|
265 |
+
.chat-message.user {
|
266 |
+
text-align: right;
|
267 |
+
color: #3498db;
|
268 |
+
}
|
269 |
+
|
270 |
+
.chat-message.agent {
|
271 |
+
text-align: left;
|
272 |
+
color: #e74c3c;
|
273 |
+
}
|
274 |
+
|
275 |
+
/* Project Management */
|
276 |
+
.project-list {
|
277 |
+
background-color: #ecf0f1;
|
278 |
+
padding: 20px;
|
279 |
+
border-radius: 5px;
|
280 |
+
max-height: 300px;
|
281 |
+
overflow-y: auto;
|
282 |
+
}
|
283 |
+
|
284 |
+
.project-item {
|
285 |
+
margin-bottom: 10px;
|
286 |
+
}
|
287 |
+
|
288 |
+
.project-item a {
|
289 |
+
color: #3498db;
|
290 |
+
text-decoration: none;
|
291 |
+
}
|
292 |
+
|
293 |
+
.project-item a:hover {
|
294 |
+
text-decoration: underline;
|
295 |
+
}
|
296 |
+
</style>
|
297 |
+
""", unsafe_allow_html=True)
|