Spaces:
Sleeping
Sleeping
Christophe Bourgoin
Claude
commited on
Commit
Β·
d978a2c
1
Parent(s):
918983a
Fix database directory creation for Hugging Face Spaces
Browse files- Ensure PROFILE_DIR is created before initializing database
- Add README_DEV.md with comprehensive development guide
- Fix error: "Failed to create database engine" on HF Spaces
This fixes the issue where HF Spaces couldn't create the
~/.agentic-content-generation directory for session storage.
π€ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- README_DEV.md +274 -0
- main.py +2 -0
README_DEV.md
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
|
| 7 |
+
- Python 3.11 or higher
|
| 8 |
+
- [uv](https://github.com/astral-sh/uv) package manager
|
| 9 |
+
- Git
|
| 10 |
+
|
| 11 |
+
## Quick Start
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
# Clone the repository
|
| 15 |
+
git clone https://github.com/ChrisBg/scientific-content-agent-interface.git
|
| 16 |
+
cd scientific-content-agent-interface
|
| 17 |
+
|
| 18 |
+
# Setup everything (create venv + install dependencies)
|
| 19 |
+
make setup
|
| 20 |
+
|
| 21 |
+
# Activate the virtual environment
|
| 22 |
+
source .venv/bin/activate
|
| 23 |
+
|
| 24 |
+
# Create your .env file
|
| 25 |
+
cp .env.example .env
|
| 26 |
+
# Add your GOOGLE_API_KEY to .env
|
| 27 |
+
|
| 28 |
+
# Run the Gradio UI
|
| 29 |
+
make run-ui
|
| 30 |
+
|
| 31 |
+
# Or run the CLI
|
| 32 |
+
make run-cli TOPIC="Your research topic"
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Available Make Commands
|
| 36 |
+
|
| 37 |
+
### Setup & Installation
|
| 38 |
+
|
| 39 |
+
```bash
|
| 40 |
+
make setup # Complete setup (venv + dependencies)
|
| 41 |
+
make venv # Create uv virtual environment
|
| 42 |
+
make install # Install production dependencies
|
| 43 |
+
make install-dev # Install development dependencies
|
| 44 |
+
make update # Update all dependencies
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### Running the Application
|
| 48 |
+
|
| 49 |
+
```bash
|
| 50 |
+
make run # Run Gradio UI (default)
|
| 51 |
+
make run-ui # Run Gradio web interface
|
| 52 |
+
make run-cli # Run CLI (add TOPIC="..." for custom topic)
|
| 53 |
+
make run-session # Resume session (requires SESSION_ID=...)
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### Profile Management
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
make profile-init # Initialize default profile
|
| 60 |
+
make profile-edit # Edit profile interactively
|
| 61 |
+
make profile-validate # Validate current profile
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Session Management
|
| 65 |
+
|
| 66 |
+
```bash
|
| 67 |
+
make sessions-list # List all sessions
|
| 68 |
+
make session-delete # Delete session (requires SESSION_ID=...)
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### Testing
|
| 72 |
+
|
| 73 |
+
```bash
|
| 74 |
+
make test # Run all tests
|
| 75 |
+
make test-unit # Run unit tests only
|
| 76 |
+
make test-integration # Run integration tests only
|
| 77 |
+
make test-fast # Run tests without slow tests
|
| 78 |
+
make test-cov # Run tests with coverage report
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
### Code Quality
|
| 82 |
+
|
| 83 |
+
```bash
|
| 84 |
+
make lint # Run ruff linter
|
| 85 |
+
make lint-fix # Run ruff and auto-fix issues
|
| 86 |
+
make format # Format code with ruff
|
| 87 |
+
make type-check # Run mypy type checker
|
| 88 |
+
make check # Run lint + type-check + fast tests
|
| 89 |
+
make all # Format + lint + type-check + test
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
### Development Workflow
|
| 93 |
+
|
| 94 |
+
```bash
|
| 95 |
+
make dev # Format and lint code
|
| 96 |
+
make pre-commit # Pre-commit checks (recommended before commit)
|
| 97 |
+
make ci # CI checks (lint + type-check + test with coverage)
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
### Deployment
|
| 101 |
+
|
| 102 |
+
```bash
|
| 103 |
+
make deploy-github MSG="commit message" # Deploy to GitHub
|
| 104 |
+
make deploy-hf MSG="commit message" # Deploy to Hugging Face
|
| 105 |
+
make deploy-both MSG="commit message" # Deploy to both
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### Cleaning
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
make clean # Clean build artifacts and cache
|
| 112 |
+
make clean-all # Clean everything including venv
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## Project Structure
|
| 116 |
+
|
| 117 |
+
```
|
| 118 |
+
scientific-content-agent/
|
| 119 |
+
βββ src/ # Source code
|
| 120 |
+
β βββ agents.py # Agent definitions
|
| 121 |
+
β βββ tools.py # Custom tools
|
| 122 |
+
β βββ config.py # Configuration
|
| 123 |
+
β βββ profile.py # User profile management
|
| 124 |
+
β βββ session_manager.py # Session persistence
|
| 125 |
+
βββ tests/ # Test suite
|
| 126 |
+
β βββ test_tools.py # Tool tests
|
| 127 |
+
βββ app.py # HF Spaces entry point
|
| 128 |
+
βββ main.py # CLI entry point
|
| 129 |
+
βββ ui_app.py # Gradio UI
|
| 130 |
+
βββ pyproject.toml # Project configuration
|
| 131 |
+
βββ Makefile # Development commands
|
| 132 |
+
βββ CLAUDE.md # Claude Code documentation
|
| 133 |
+
βββ README.md # User-facing README
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
## Development Workflow
|
| 137 |
+
|
| 138 |
+
1. **Create a feature branch**
|
| 139 |
+
```bash
|
| 140 |
+
git checkout -b feature/my-feature
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
2. **Make your changes**
|
| 144 |
+
- Edit code in `src/`
|
| 145 |
+
- Add tests in `tests/`
|
| 146 |
+
|
| 147 |
+
3. **Format and lint**
|
| 148 |
+
```bash
|
| 149 |
+
make dev
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
4. **Run tests**
|
| 153 |
+
```bash
|
| 154 |
+
make test
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
5. **Pre-commit checks**
|
| 158 |
+
```bash
|
| 159 |
+
make pre-commit
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
6. **Commit and push**
|
| 163 |
+
```bash
|
| 164 |
+
git add .
|
| 165 |
+
git commit -m "Your message"
|
| 166 |
+
git push origin feature/my-feature
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
## Running Tests
|
| 170 |
+
|
| 171 |
+
### Unit Tests
|
| 172 |
+
```bash
|
| 173 |
+
# Run all unit tests
|
| 174 |
+
make test-unit
|
| 175 |
+
|
| 176 |
+
# Run specific test file
|
| 177 |
+
uv run pytest tests/test_tools.py
|
| 178 |
+
|
| 179 |
+
# Run specific test
|
| 180 |
+
uv run pytest tests/test_tools.py::TestFormatForPlatform::test_format_blog
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
### Integration Tests
|
| 184 |
+
```bash
|
| 185 |
+
# Run all integration tests (requires internet)
|
| 186 |
+
make test-integration
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
### With Coverage
|
| 190 |
+
```bash
|
| 191 |
+
make test-cov
|
| 192 |
+
# View HTML report: open htmlcov/index.html
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
## Code Quality Tools
|
| 196 |
+
|
| 197 |
+
### Ruff (Linter + Formatter)
|
| 198 |
+
```bash
|
| 199 |
+
# Check code
|
| 200 |
+
make lint
|
| 201 |
+
|
| 202 |
+
# Auto-fix issues
|
| 203 |
+
make lint-fix
|
| 204 |
+
|
| 205 |
+
# Format code
|
| 206 |
+
make format
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
### Mypy (Type Checker)
|
| 210 |
+
```bash
|
| 211 |
+
make type-check
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
## Environment Variables
|
| 215 |
+
|
| 216 |
+
Create a `.env` file with:
|
| 217 |
+
|
| 218 |
+
```bash
|
| 219 |
+
GOOGLE_API_KEY=your_api_key_here
|
| 220 |
+
GOOGLE_GENAI_USE_VERTEXAI=FALSE
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
Get your API key from: https://aistudio.google.com/app/api_keys
|
| 224 |
+
|
| 225 |
+
## Troubleshooting
|
| 226 |
+
|
| 227 |
+
### Virtual environment issues
|
| 228 |
+
```bash
|
| 229 |
+
make clean-all
|
| 230 |
+
make setup
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
### Dependency conflicts
|
| 234 |
+
```bash
|
| 235 |
+
make update
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
### Test failures
|
| 239 |
+
```bash
|
| 240 |
+
# Run tests with verbose output
|
| 241 |
+
uv run pytest -vv
|
| 242 |
+
|
| 243 |
+
# Run with debugging
|
| 244 |
+
uv run pytest --pdb
|
| 245 |
+
```
|
| 246 |
+
|
| 247 |
+
## Contributing
|
| 248 |
+
|
| 249 |
+
1. Fork the repository
|
| 250 |
+
2. Create your feature branch
|
| 251 |
+
3. Make changes and add tests
|
| 252 |
+
4. Run `make pre-commit` to ensure quality
|
| 253 |
+
5. Push to your fork
|
| 254 |
+
6. Create a Pull Request
|
| 255 |
+
|
| 256 |
+
## CI/CD
|
| 257 |
+
|
| 258 |
+
The project uses:
|
| 259 |
+
- **GitHub**: Source code repository
|
| 260 |
+
- **Hugging Face Spaces**: Live demo deployment
|
| 261 |
+
|
| 262 |
+
Both remotes are configured:
|
| 263 |
+
- `github`: https://github.com/ChrisBg/scientific-content-agent-interface
|
| 264 |
+
- `origin`: https://huggingface.co/spaces/Chris30/scientific-content-agent
|
| 265 |
+
|
| 266 |
+
Use `make deploy-both MSG="message"` to deploy to both.
|
| 267 |
+
|
| 268 |
+
## Resources
|
| 269 |
+
|
| 270 |
+
- [uv documentation](https://github.com/astral-sh/uv)
|
| 271 |
+
- [Ruff documentation](https://docs.astral.sh/ruff/)
|
| 272 |
+
- [pytest documentation](https://docs.pytest.org/)
|
| 273 |
+
- [Google ADK documentation](https://github.com/google/adk)
|
| 274 |
+
- [Gradio documentation](https://gradio.app/docs)
|
main.py
CHANGED
|
@@ -68,6 +68,8 @@ async def run_content_generation(topic: str, preferences: dict = None, session_i
|
|
| 68 |
)
|
| 69 |
|
| 70 |
# Initialize persistent session service
|
|
|
|
|
|
|
| 71 |
db_path = PROFILE_DIR / "sessions.db"
|
| 72 |
db_url = f"sqlite:///{db_path}"
|
| 73 |
session_service = DatabaseSessionService(db_url=db_url)
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
# Initialize persistent session service
|
| 71 |
+
# Ensure the directory exists (important for HF Spaces)
|
| 72 |
+
PROFILE_DIR.mkdir(parents=True, exist_ok=True)
|
| 73 |
db_path = PROFILE_DIR / "sessions.db"
|
| 74 |
db_url = f"sqlite:///{db_path}"
|
| 75 |
session_service = DatabaseSessionService(db_url=db_url)
|