Spaces:
Sleeping
A newer version of the Gradio SDK is available:
6.9.0
π€ Memory Chat - Hugging Face Spaces
A conversational AI application built with Hugging Face models that records and remembers user memories. Deployed on Hugging Face Spaces with persistent storage.
π Features
- π€ Hugging Face Integration: Uses DialoGPT for natural conversations
- πΎ Memory System: Automatically records important information from conversations
- π Memory Management: View, search, and manage your memories
- π Smart Retrieval: AI recalls relevant memories during conversations
- βοΈ Persistent Storage: Memories persist between sessions on the Space
π― How It Works
- Conversation: Chat naturally with the AI using Hugging Face models
- Memory Detection: The system automatically detects important information using keywords and patterns
- Memory Storage: Important details are stored as vector embeddings with metadata
- Memory Retrieval: When relevant, the AI recalls past memories to provide context
- Timeline View: View your memory timeline and statistics
π‘ Memory Recording Examples
The system automatically remembers:
- Personal preferences: "I love pizza and hate mushrooms"
- Important facts: "My birthday is December 15th"
- Locations: "I live in New York"
- Work/Study: "I work at Google", "I study computer science"
- Favorites: "My favorite color is blue"
ποΈ Architecture
space_app.py # Main application (optimized for HF Spaces)
βββ memory_manager.py # Memory storage and retrieval
βββ chat_interface.py # Hugging Face model integration
βββ config.py # Configuration settings
βββ space_requirements.txt # Dependencies for HF Spaces
π¦ Dependencies
- Core: torch, transformers, gradio
- Memory: faiss-cpu, sentence-transformers
- Utilities: numpy, pandas, python-dotenv, rich
π§ Local Development
Installation
- Clone this repository
- Install dependencies:
pip install -r space_requirements.txt - Run the application:
python space_app.py
Testing
Run the test script to verify everything works:
python test_app.py
βοΈ Deploying to Hugging Face Spaces
Option 1: Direct Upload (Recommended)
Go to Hugging Face Spaces
Click "Create new Space"
Choose a name for your Space
Select "Gradio" as the Space type
Choose "Public" visibility
Upload the files:
space_app.pyβ Rename toapp.pymemory_manager.pychat_interface.pyconfig.pyspace_requirements.txtβ Rename torequirements.txtREADME_SPACES.mdβ Rename toREADME.md
Commit and push to create your Space!
Option 2: Git Clone
Create a new Space on Hugging Face
Clone your Space locally:
git clone https://huggingface.co/spaces/your-username/your-space-name cd your-space-nameCopy the files:
cp /path/to/your/hf-memory-chat/space_app.py app.py cp /path/to/your/hf-memory-chat/memory_manager.py . cp /path/to/your/hf-memory-chat/chat_interface.py . cp /path/to/your/hf-memory-chat/config.py . cp /path/to/your/hf-memory-chat/space_requirements.txt requirements.txt cp /path/to/your/hf-memory-chat/README_SPACES.md README.mdPush to HF:
git add . git commit -m "Initial commit: Memory Chat application" git push origin main
βοΈ Configuration
Environment Variables
HF Spaces automatically sets up the environment, but you can customize:
PORT: The port to run on (automatically set by Spaces)SPACE_ID: Space identifier (automatically set)
Model Configuration
The application uses microsoft/DialoGPT-small by default, which is optimized for:
- Fast loading times
- Good conversational quality
- Lower resource usage
π§ Memory System Details
Storage
- Location:
/tmp/memorieson HF Spaces (persistent) - Format: JSON for memories, Markdown for timeline
- Indexing: FAISS for fast similarity search
Memory Types
- General: General information and facts
- Conversation: Important details from chats
- Preferences: Likes, dislikes, favorites
- Important: Critical information marked as important
Automatic Recording
Memories are automatically recorded when:
- User explicitly requests memory recording
- Important keywords are detected
- Personal information patterns are found
- High importance score is calculated
π¨ UI Features
Chat Interface
- Clean, responsive design
- Send messages with Enter key
- Clear conversation history
- Automatic memory recording indicators
Memory Management
- View memory statistics
- See recent memories
- Clear all memories
- Refresh memory display
About Section
- Detailed documentation
- Usage instructions
- Feature explanations
π Performance Optimizations
For HF Spaces
- Model Selection: Uses DialoGPT-small for faster loading
- Memory Storage: Optimized for persistent storage
- Error Handling: Graceful fallbacks for model loading
- Resource Management: Efficient memory usage
Local Development
- GPU Support: Automatic GPU detection if available
- Caching: Model loading optimization
- Error Recovery: Fallback to simple text generation
π Troubleshooting
Common Issues
Model Loading Errors
- Usually temporary network issues
- Application falls back to simple text generation
- Try refreshing the page
Memory Not Persisting
- Ensure you're using the correct app.py file
- Check that
/tmp/memoriesdirectory is writable - Verify Space has sufficient storage
Slow Responses
- First-time model loading can be slow
- Subsequent requests are cached
- Consider using smaller models for faster responses
Getting Help
- Hugging Face Community: HF Forums
- GitHub Issues: Report bugs and feature requests
- Documentation: Check the About section in the app
π License
MIT License - see LICENSE file for details
π€ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for your changes
- Submit a pull request
π Acknowledgments
- Hugging Face: For providing the amazing ecosystem and Spaces platform
- Microsoft: For the DialoGPT models
- FAISS Team: For efficient similarity search
- Gradio Team: For the excellent UI framework
Built with β€οΈ using Hugging Face, Gradio, and the power of AI memories