Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -65,7 +65,7 @@ AUDIO_CACHE_DIR = "audio_cache"
|
|
65 |
AUDIO_DIR = "audio_logs"
|
66 |
|
67 |
# World Builder Constants
|
68 |
-
|
69 |
HISTORY_LOG_DIR = "history_logs"
|
70 |
PLOT_WIDTH = 50.0
|
71 |
PLOT_DEPTH = 50.0
|
@@ -104,7 +104,8 @@ def get_current_time_str(tz='UTC'):
|
|
104 |
return now_aware.strftime('%Y%m%d_%H%M%S')
|
105 |
|
106 |
def clean_filename_part(text, max_len=30):
|
107 |
-
if not isinstance(text, str):
|
|
|
108 |
text = re.sub(r'\s+', '_', text)
|
109 |
text = re.sub(r'[^\w\-.]', '', text)
|
110 |
return text[:max_len]
|
@@ -127,6 +128,15 @@ def run_async(async_func, *args, **kwargs):
|
|
127 |
def ensure_dir(dir_path):
|
128 |
os.makedirs(dir_path, exist_ok=True)
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
# ==============================================================================
|
131 |
# World State File Handling (Markdown + JSON)
|
132 |
# ==============================================================================
|
@@ -1053,7 +1063,7 @@ def render_main_content():
|
|
1053 |
parsed = parse_world_filename(os.path.join(SAVED_WORLDS_DIR, current_file_basename))
|
1054 |
save_label = f"Save Changes to '{parsed['name']}'"
|
1055 |
if st.button(save_label, key="save_current_world", help=f"Overwrite '{current_file_basename}'"):
|
1056 |
-
with st.spinner(f"Overwriting {
|
1057 |
if save_world_state_to_md(current_file_basename):
|
1058 |
st.success("Current world saved!")
|
1059 |
else:
|
|
|
65 |
AUDIO_DIR = "audio_logs"
|
66 |
|
67 |
# World Builder Constants
|
68 |
+
SAVED_WORLDS_DIR = "saved_worlds" # Corrected from SAVED_WORLDS0
|
69 |
HISTORY_LOG_DIR = "history_logs"
|
70 |
PLOT_WIDTH = 50.0
|
71 |
PLOT_DEPTH = 50.0
|
|
|
104 |
return now_aware.strftime('%Y%m%d_%H%M%S')
|
105 |
|
106 |
def clean_filename_part(text, max_len=30):
|
107 |
+
if not isinstance(text, str):
|
108 |
+
text = "invalid_name"
|
109 |
text = re.sub(r'\s+', '_', text)
|
110 |
text = re.sub(r'[^\w\-.]', '', text)
|
111 |
return text[:max_len]
|
|
|
128 |
def ensure_dir(dir_path):
|
129 |
os.makedirs(dir_path, exist_ok=True)
|
130 |
|
131 |
+
def generate_filename(content, username, extension):
|
132 |
+
timestamp = get_current_time_str()
|
133 |
+
content_hash = hashlib.md5(content[:150].encode()).hexdigest()[:6]
|
134 |
+
clean_username = clean_filename_part(username)
|
135 |
+
return f"{clean_username}_{timestamp}_{content_hash}.{extension}"
|
136 |
+
|
137 |
+
def format_timestamp_prefix(prefix):
|
138 |
+
return f"{prefix}_{get_current_time_str()}"
|
139 |
+
|
140 |
# ==============================================================================
|
141 |
# World State File Handling (Markdown + JSON)
|
142 |
# ==============================================================================
|
|
|
1063 |
parsed = parse_world_filename(os.path.join(SAVED_WORLDS_DIR, current_file_basename))
|
1064 |
save_label = f"Save Changes to '{parsed['name']}'"
|
1065 |
if st.button(save_label, key="save_current_world", help=f"Overwrite '{current_file_basename}'"):
|
1066 |
+
with st.spinner(f"Overwriting {current_file_basename}..."):
|
1067 |
if save_world_state_to_md(current_file_basename):
|
1068 |
st.success("Current world saved!")
|
1069 |
else:
|