Spaces:
Sleeping
Sleeping
File size: 1,556 Bytes
472739a 71a1c59 472739a 71a1c59 472739a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import json
import os
from datetime import datetime
from utils.config import OUTPUT_DIR
HISTORY_FILE = os.path.join(OUTPUT_DIR, "history.json")
def load_history():
"""Load podcast generation history from JSON file"""
if not os.path.exists(HISTORY_FILE):
return []
try:
with open(HISTORY_FILE, 'r') as f:
return json.load(f)
except Exception as e:
print(f"Error loading history: {e}")
return []
def save_to_history(url, audio_path, script_length):
"""Save a podcast generation to history"""
history = load_history()
entry = {
"url": url,
"audio_path": audio_path,
"script_length": script_length,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"audio_filename": os.path.basename(audio_path)
}
history.append(entry)
try:
with open(HISTORY_FILE, 'w') as f:
json.dump(history, f, indent=2)
print(f"✓ Saved to history: {url}")
except Exception as e:
print(f"Error saving to history: {e}")
def get_history_items():
"""Get history items formatted for Gradio display"""
history = load_history()
if not history:
return []
# Return in reverse order (newest first)
items = []
for entry in reversed(history):
items.append({
"timestamp": entry["timestamp"],
"url": entry["url"],
"audio_path": entry["audio_path"],
"script_length": entry.get("script_length", "N/A")
})
return items
|