Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -190,7 +190,57 @@ def clean_text_for_filename(text: str) -> str:
|
|
| 190 |
filtered = [w for w in words if len(w) > 3 and w not in stop_short]
|
| 191 |
return '_'.join(filtered)[:200]
|
| 192 |
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
prefix = format_timestamp_prefix() + "_"
|
| 195 |
combined = (prompt + " " + response).strip()
|
| 196 |
info_terms = get_high_info_terms(combined, top_n=10)
|
|
@@ -202,7 +252,7 @@ def generate_filename(prompt, response, file_type="md"):
|
|
| 202 |
full_name = full_name[:150]
|
| 203 |
return f"{prefix}{full_name}.{file_type}"
|
| 204 |
|
| 205 |
-
def
|
| 206 |
filename = generate_filename(prompt.strip(), response.strip(), file_type)
|
| 207 |
with open(filename, 'w', encoding='utf-8') as f:
|
| 208 |
f.write(prompt + "\n\n" + response)
|
|
|
|
| 190 |
filtered = [w for w in words if len(w) > 3 and w not in stop_short]
|
| 191 |
return '_'.join(filtered)[:200]
|
| 192 |
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def generate_filename(prompt, response, file_type="md", max_length=120):
|
| 196 |
+
"""
|
| 197 |
+
Generate a shortened filename by:
|
| 198 |
+
1. Extracting high-info terms
|
| 199 |
+
2. Creating a smaller snippet
|
| 200 |
+
3. Cleaning & joining them
|
| 201 |
+
4. Truncating if needed
|
| 202 |
+
"""
|
| 203 |
+
prefix = format_timestamp_prefix() + "_"
|
| 204 |
+
|
| 205 |
+
# Combine prompt+response but keep it from getting huge:
|
| 206 |
+
combined_text = (prompt + " " + response)[:2000] # limit huge text input
|
| 207 |
+
|
| 208 |
+
# Grab top info terms (10 might be too many; reduce if it still runs long)
|
| 209 |
+
info_terms = get_high_info_terms(combined_text, top_n=8)
|
| 210 |
+
|
| 211 |
+
# Make a small snippet (truncate at 80 chars total)
|
| 212 |
+
snippet = (prompt[:40] + " " + response[:40]).strip()
|
| 213 |
+
snippet_cleaned = clean_text_for_filename(snippet)
|
| 214 |
+
|
| 215 |
+
# Combine them into a single string, joined by underscores
|
| 216 |
+
name_parts = info_terms + [snippet_cleaned]
|
| 217 |
+
full_name = '_'.join(name_parts).strip('_')
|
| 218 |
+
|
| 219 |
+
# Finally, ensure we do not exceed max_length
|
| 220 |
+
# (minus room for prefix and file extension)
|
| 221 |
+
leftover_chars = max_length - len(prefix) - len(file_type) - 1
|
| 222 |
+
if len(full_name) > leftover_chars:
|
| 223 |
+
full_name = full_name[:leftover_chars]
|
| 224 |
+
|
| 225 |
+
return f"{prefix}{full_name}.{file_type}"
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def create_file(prompt, response, file_type="md"):
|
| 229 |
+
"""
|
| 230 |
+
Create a file using the shortened filename from generate_filename().
|
| 231 |
+
"""
|
| 232 |
+
filename = generate_filename(prompt.strip(), response.strip(), file_type)
|
| 233 |
+
with open(filename, 'w', encoding='utf-8') as f:
|
| 234 |
+
f.write(prompt + "\n\n" + response)
|
| 235 |
+
return filename
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def generate_filename_old(prompt, response, file_type="md"):
|
| 244 |
prefix = format_timestamp_prefix() + "_"
|
| 245 |
combined = (prompt + " " + response).strip()
|
| 246 |
info_terms = get_high_info_terms(combined, top_n=10)
|
|
|
|
| 252 |
full_name = full_name[:150]
|
| 253 |
return f"{prefix}{full_name}.{file_type}"
|
| 254 |
|
| 255 |
+
def create_file_old(prompt, response, file_type="md"):
|
| 256 |
filename = generate_filename(prompt.strip(), response.strip(), file_type)
|
| 257 |
with open(filename, 'w', encoding='utf-8') as f:
|
| 258 |
f.write(prompt + "\n\n" + response)
|