acecalisto3 commited on
Commit
1c351dd
·
verified ·
1 Parent(s): ddd08c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +194 -226
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 = "YOUR_HUGGING_FACE_API_KEY" # Replace with your actual 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", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
98
-
99
- if app_mode == "AI Agent Creator":
100
- # AI Agent Creator
101
- st.header("Create an AI Agent from Text")
102
-
103
- st.subheader("From Text")
104
- agent_name = st.text_input("Enter agent name:")
105
- text_input = st.text_area("Enter skills (one per line):")
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
- # Project Management
133
- st.subheader("Project Management")
134
- project_name_input = st.text_input("Enter Project Name:")
135
- if st.button("Create Project"):
136
- status = workspace_interface(project_name_input)
137
- st.write(status)
138
-
139
- code_to_add = st.text_area("Enter Code to Add to Workspace:", height=150)
140
- file_name_input = st.text_input("Enter File Name (e.g., 'app.py'):")
141
- if st.button("Add Code"):
142
- status = add_code_to_workspace(project_name_input, code_to_add, file_name_input)
143
- st.write(status)
144
-
145
- # Display Chat History
146
- st.subheader("Chat History")
147
- chat_history = display_chat_history(st.session_state.chat_history)
148
- st.text_area("Chat History", value=chat_history, height=200)
149
-
150
- # Display Workspace Projects
151
- st.subheader("Workspace Projects")
152
- workspace_projects = display_workspace_projects(st.session_state.workspace_projects)
153
- st.text_area("Workspace Projects", value=workspace_projects, height=200)
154
-
155
- elif app_mode == "Workspace Chat App":
156
- # Workspace Chat App
157
- st.header("Workspace Chat App")
158
-
159
- # Chat Interface with AI Agents
160
- st.subheader("Chat with AI Agents")
161
- selected_agent = st.selectbox("Select an AI agent", st.session_state.available_agents)
162
- agent_chat_input = st.text_area("Enter your message for the agent:")
163
- if st.button("Send to Agent"):
164
- response = process_input(agent_chat_input)
165
- st.session_state.chat_history.append((agent_chat_input, response))
166
- st.write(f"{selected_agent}: {response}")
167
-
168
- # Code Generation
169
- st.subheader("Code Generation")
170
- code_idea = st.text_input("Enter your code idea:")
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, hf_token)
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
- # Launch the Streamlit app
193
- st.markdown("""
194
- <style>
195
- /* Advanced and Accommodating CSS */
196
- body {
197
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
198
- background-color: #f4f4f9;
199
- color: #333;
200
- margin: 0;
201
- padding: 0;
202
- }
203
-
204
- h1, h2, h3, h4, h5, h6 {
205
- color: #333;
206
- }
207
-
208
- .container {
209
- width: 90%;
210
- margin: 0 auto;
211
- padding: 20px;
212
- }
213
-
214
- /* Navigation Sidebar */
215
- .sidebar {
216
- background-color: #2c3e50;
217
- color: #ecf0f1;
218
- padding: 20px;
219
- height: 100vh;
220
- position: fixed;
221
- top: 0;
222
- left: 0;
223
- width: 250px;
224
- overflow-y: auto;
225
- }
226
-
227
- .sidebar a {
228
- color: #ecf0f1;
229
- text-decoration: none;
230
- display: block;
231
- padding: 10px 0;
232
- }
233
-
234
- .sidebar a:hover {
235
- background-color: #34495e;
236
- border-radius: 5px;
237
- }
238
-
239
- /* Main Content */
240
- .main-content {
241
- margin-left: 270px;
242
- padding: 20px;
243
- }
244
-
245
- /* Buttons */
246
- button {
247
- background-color: #3498db;
248
- color: #fff;
249
- border: none;
250
- padding: 10px 20px;
251
- border-radius: 5px;
252
- cursor: pointer;
253
- font-size: 16px;
254
- }
255
-
256
- button:hover {
257
- background-color: #2980b9;
258
- }
259
-
260
- /* Text Areas and Inputs */
261
- textarea, input[type="text"] {
262
- width: 100%;
263
- padding: 10px;
264
- margin: 10px 0;
265
- border: 1px solid #ddd;
266
- border-radius: 5px;
267
- box-sizing: border-box;
268
- }
269
-
270
- textarea:focus, input[type="text"]:focus {
271
- border-color: #3498db;
272
- outline: none;
273
- }
274
-
275
- /* Terminal Output */
276
- .code-output {
277
- background-color: #1e1e1e;
278
- color: #dcdcdc;
279
- padding: 20px;
280
- border-radius: 5px;
281
- font-family: 'Courier New', Courier, monospace;
282
- }
283
-
284
- /* Chat History */
285
- .chat-history {
286
- background-color: #ecf0f1;
287
- padding: 20px;
288
- border-radius: 5px;
289
- max-height: 300px;
290
- overflow-y: auto;
291
- }
292
-
293
- .chat-message {
294
- margin-bottom: 10px;
295
- }
296
-
297
- .chat-message.user {
298
- text-align: right;
299
- color: #3498db;
300
- }
301
-
302
- .chat-message.agent {
303
- text-align: left;
304
- color: #e74c3c;
305
- }
306
-
307
- /* Project Management */
308
- .project-list {
309
- background-color: #ecf0f1;
310
- padding: 20px;
311
- border-radius: 5px;
312
- max-height: 300px;
313
- overflow-y: auto;
314
- }
315
-
316
- .project-item {
317
- margin-bottom: 10px;
318
- }
319
-
320
- .project-item a {
321
- color: #3498db;
322
- text-decoration: none;
323
- }
324
-
325
- .project-item a:hover {
326
- text-decoration: underline;
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)