Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -94,6 +94,42 @@ def is_project_loaded():
|
|
| 94 |
pkl_files = [f for f in os.listdir(extraction_dir) if f.endswith('.pkl')]
|
| 95 |
return bool(pkl_files)
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# --- Gradio UI Components ---
|
| 98 |
|
| 99 |
# Chat Interface
|
|
@@ -122,27 +158,11 @@ def chat_ui(query, history, mode):
|
|
| 122 |
response = "An error occurred during processing. Please check the logs."
|
| 123 |
|
| 124 |
if mode == "developer":
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
if chunk.strip().startswith("BEGIN FILE:"):
|
| 131 |
-
# Extract filepath and code content
|
| 132 |
-
filepath = chunk.split("BEGIN FILE:")[1].split("\n")[0].strip()
|
| 133 |
-
code_content = chunk.replace(f"BEGIN FILE: {filepath}\n", "").strip()
|
| 134 |
-
|
| 135 |
-
# Remove "END FILE:" and its associated filepath if present at the end.
|
| 136 |
-
if code_content.rfind("END FILE:") != -1:
|
| 137 |
-
end_file_index = code_content.rfind("END FILE:")
|
| 138 |
-
code_content = code_content[:end_file_index].strip()
|
| 139 |
-
|
| 140 |
-
formatted_response_parts.append(f"**{filepath}:**\n`python\n{code_content}\n`")
|
| 141 |
-
elif chunk.strip():
|
| 142 |
-
formatted_response_parts.append(chunk.strip())
|
| 143 |
-
|
| 144 |
-
# Join the formatted parts with separators
|
| 145 |
-
formatted_response = "\n---\n".join(formatted_response_parts)
|
| 146 |
|
| 147 |
else:
|
| 148 |
# Format the output for non-developer modes
|
|
|
|
| 94 |
pkl_files = [f for f in os.listdir(extraction_dir) if f.endswith('.pkl')]
|
| 95 |
return bool(pkl_files)
|
| 96 |
|
| 97 |
+
# --- Helper Function for Developer Mode ---
|
| 98 |
+
def extract_files_from_response(response):
|
| 99 |
+
"""
|
| 100 |
+
Parses the LLM response to extract file paths and their corresponding code content.
|
| 101 |
+
|
| 102 |
+
Args:
|
| 103 |
+
response (str): The raw response string from the LLM.
|
| 104 |
+
|
| 105 |
+
Returns:
|
| 106 |
+
dict: A dictionary where keys are file paths and values are the code content of each file.
|
| 107 |
+
"""
|
| 108 |
+
files = {}
|
| 109 |
+
current_file = None
|
| 110 |
+
current_content = []
|
| 111 |
+
|
| 112 |
+
for line in response.splitlines():
|
| 113 |
+
if line.startswith("--- BEGIN FILE:"):
|
| 114 |
+
if current_file is not None:
|
| 115 |
+
# Save previous file content
|
| 116 |
+
files[current_file] = "\n".join(current_content)
|
| 117 |
+
|
| 118 |
+
# Start a new file
|
| 119 |
+
current_file = line.replace("--- BEGIN FILE:", "").strip()
|
| 120 |
+
current_content = []
|
| 121 |
+
elif line.startswith("--- END FILE:"):
|
| 122 |
+
if current_file is not None:
|
| 123 |
+
# Save current file content
|
| 124 |
+
files[current_file] = "\n".join(current_content)
|
| 125 |
+
current_file = None
|
| 126 |
+
current_content = []
|
| 127 |
+
elif current_file is not None:
|
| 128 |
+
# Append line to current file content
|
| 129 |
+
current_content.append(line)
|
| 130 |
+
|
| 131 |
+
return files
|
| 132 |
+
|
| 133 |
# --- Gradio UI Components ---
|
| 134 |
|
| 135 |
# Chat Interface
|
|
|
|
| 158 |
response = "An error occurred during processing. Please check the logs."
|
| 159 |
|
| 160 |
if mode == "developer":
|
| 161 |
+
extracted_files = extract_files_from_response(response)
|
| 162 |
+
formatted_response = ""
|
| 163 |
+
|
| 164 |
+
for filepath, content in extracted_files.items():
|
| 165 |
+
formatted_response += f"## {filepath}\n`\n{content}\n`\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
else:
|
| 168 |
# Format the output for non-developer modes
|