acecalisto3 commited on
Commit
80b15f5
·
verified ·
1 Parent(s): 9491bbc

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +23 -20
app2.py CHANGED
@@ -149,26 +149,29 @@ if st.session_state.GOOGLE_API_KEY:
149
  st.warning("Please enter a project name")
150
 
151
  # Code Editor
152
- st.subheader("Code Editor")
153
- if st.session_state.workspace_projects:
154
- selected_project = st.selectbox("Select file to edit", files) if files else None
155
- if selected_file:
156
- file_content = next((file['code'] for file in st.session_state.workspace_projects[selected_project]['files'] if file['file_name'] == selected_file), "")
157
- edited_code = st.text_area("Edit code", value=file_content, height=300)
158
-
159
- # Using st.text_area for now
160
- if st.button("Save Changes"):
161
- for file in st.session_state.workspace_projects[selected_project]['files']:
162
- if file['file_name'] == selected_file:
163
- file['code'] = edited_code
164
- # Save the changes to the actual file in the project directory
165
- file_path = os.path.join(selected_project, selected_file)
166
- with open(file_path, "w") as f:
167
- f.write(edited_code)
168
- st.success("Changes saved successfully!")
169
- break
170
- else:
171
- st.info("No files in the project. Use the chat interface to generate code.")
 
 
 
172
  else:
173
  st.info("No projects created yet. Create a project to start coding.")
174
 
 
149
  st.warning("Please enter a project name")
150
 
151
  # Code Editor
152
+ st.subheader("Code Editor")
153
+ if st.session_state.workspace_projects:
154
+ selected_project = st.selectbox("Select project", list(st.session_state.workspace_projects.keys()))
155
+ if selected_project:
156
+ files = [file['file_name'] for file in st.session_state.workspace_projects[selected_project]['files']]
157
+ selected_file = st.selectbox("Select file to edit", files) if files else None
158
+ if selected_file:
159
+ file_content = next((file['code'] for file in st.session_state.workspace_projects[selected_project]['files'] if file['file_name'] == selected_file), "")
160
+ edited_code = st.text_area("Edit code", value=file_content, height=300)
161
+ if st.button("Save Changes"):
162
+ for file in st.session_state.workspace_projects[selected_project]['files']:
163
+ if file['file_name'] == selected_file:
164
+ file['code'] = edited_code
165
+ # Save the changes to the actual file in the project directory
166
+ file_path = os.path.join(selected_project, selected_file)
167
+ with open(file_path, "w") as f:
168
+ f.write(edited_code)
169
+ st.success("Changes saved successfully!")
170
+ break
171
+ else:
172
+ st.info("No files in the project. Use the chat interface to generate code.")
173
+ else:
174
+ st.info("No projects created yet. Create a project to start coding.")
175
  else:
176
  st.info("No projects created yet. Create a project to start coding.")
177