Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,23 +106,28 @@ def create_file(filename, prompt, response, should_save=True):
|
|
| 106 |
# Step 3: Check if the response contains Python code
|
| 107 |
has_python_code = bool(re.search(r"```python([\s\S]*?)```", response))
|
| 108 |
|
|
|
|
| 109 |
# Step 4: Write files based on type
|
| 110 |
if ext in ['.txt', '.htm', '.md']:
|
| 111 |
-
#
|
| 112 |
-
|
| 113 |
-
file.write(prompt)
|
| 114 |
|
| 115 |
-
#
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
with open(f"{base_filename}-Code.py", 'w') as file:
|
| 125 |
-
file.write(python_code)
|
| 126 |
|
| 127 |
|
| 128 |
def create_file_old(filename, prompt, response, should_save=True):
|
|
|
|
| 106 |
# Step 3: Check if the response contains Python code
|
| 107 |
has_python_code = bool(re.search(r"```python([\s\S]*?)```", response))
|
| 108 |
|
| 109 |
+
|
| 110 |
# Step 4: Write files based on type
|
| 111 |
if ext in ['.txt', '.htm', '.md']:
|
| 112 |
+
# Initialize the combined content
|
| 113 |
+
combined_content = ""
|
|
|
|
| 114 |
|
| 115 |
+
# Add Prompt with markdown title and emoji
|
| 116 |
+
combined_content += "# Prompt 📝\n" + prompt + "\n\n"
|
| 117 |
+
|
| 118 |
+
# Add Response with markdown title and emoji
|
| 119 |
+
combined_content += "# Response 💬\n" + response + "\n\n"
|
| 120 |
+
|
| 121 |
+
# Check for Python code or other resources and add them with markdown title and emoji
|
| 122 |
+
resources = re.findall(r"```([\s\S]*?)```", response)
|
| 123 |
+
for resource in resources:
|
| 124 |
+
# Add Resource title with markdown and emoji
|
| 125 |
+
combined_content += "# Resource 🛠️\n" + "```" + resource + "```\n\n"
|
| 126 |
+
|
| 127 |
+
# Write the combined content into one file
|
| 128 |
+
with open(f"{base_filename}-Combined.md", 'w') as file:
|
| 129 |
+
file.write(combined_content)
|
| 130 |
|
|
|
|
|
|
|
| 131 |
|
| 132 |
|
| 133 |
def create_file_old(filename, prompt, response, should_save=True):
|