akhaliq's picture
akhaliq HF Staff
Deploy from anycoder
bed1072 verified
# utils.py - Additional utility functions (not currently used but available for extension)
def export_todos(filename: str = "todos_backup.json"):
"""Export todos to a backup file"""
import json
from datetime import datetime
from app import load_todos
todos = load_todos()
backup_data = {
"exported_at": datetime.now().isoformat(),
"todos": todos
}
try:
with open(filename, 'w') as f:
json.dump(backup_data, f, indent=2)
return f"βœ… Todos exported to {filename}"
except Exception as e:
return f"❌ Export failed: {str(e)}"
def import_todos(filename: str):
"""Import todos from a backup file"""
import json
from app import save_todos
try:
with open(filename, 'r') as f:
data = json.load(f)
todos = data.get("todos", [])
save_todos(todos)
return f"βœ… Imported {len(todos)} todos"
except Exception as e:
return f"❌ Import failed: {str(e)}"
This Gradio Todo App features:
βœ… **Core Functionality**
- Add todos with priority levels (1-3)
- Toggle completion status
- Delete individual todos
- Clear all completed todos
- Persistent storage (JSON file)
βœ… **Modern UI**
- Clean, responsive Blocks layout
- Emojis and visual priority indicators
- Real-time updates
- Status messages
- Professional theming
βœ… **User Experience**
- Intuitive priority slider
- Helpful placeholders and labels
- Auto-clear input after adding
- Sorted display (priority + ID)
- Loading initial state
βœ… **Production Ready**
- Error handling
- File persistence across sessions
- Proper state management
- Export/import utilities (in utils.py)
Simply run `python app.py` and your Todo app is live! πŸ“±βœ¨