awacke1 commited on
Commit
efe9bd5
Β·
1 Parent(s): 5fbafa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
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
- # Create Prompt file
112
- with open(f"{base_filename}-Prompt.txt", 'w') as file:
113
- file.write(prompt)
114
 
115
- # Create Response file
116
- with open(f"{base_filename}-Response.md", 'w') as file:
117
- file.write(response)
118
-
119
- # Create Code file if Python code is present
120
- if has_python_code:
121
- # Extract Python code from the response
122
- python_code = re.findall(r"```python([\s\S]*?)```", response)[0].strip()
 
 
 
 
 
 
 
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):