# 🎨 Napkin AI API Playground

<div align="center">

![Napkin AI](https://img.shields.io/badge/Napkin%20AI-API-FF6B6B?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0iI0ZGNkI2QiIgZD0iTTEyIDJDNi40OCAyIDIgNi40OCAyIDEyczQuNDggMTAgMTAgMTAgMTAtNC40OCAxMC0xMFMxNy41MiAyIDEyIDJ6bTAgMThjLTQuNDEgMC04LTMuNTktOC04czMuNTktOCA4LTggOCAzLjU5IDggOC0zLjU5IDgtOCA4eiIvPjwvc3ZnPg==)
![Version](https://img.shields.io/badge/version-0.3.2-purple?style=for-the-badge&logo=github)
![Status](https://img.shields.io/badge/status-Production%20Ready-success?style=for-the-badge&logo=statuspage)

### 🛠️ Tech Stack

![Python](https://img.shields.io/badge/Python-3.10%2B-3776AB?style=for-the-badge&logo=python&logoColor=white)
![Poetry](https://img.shields.io/badge/Poetry-60A5FA?style=for-the-badge&logo=poetry&logoColor=white)
![Streamlit](https://img.shields.io/badge/Streamlit-FF4B4B?style=for-the-badge&logo=streamlit&logoColor=white)
![Typer](https://img.shields.io/badge/Typer-CLI-4B8BBE?style=for-the-badge&logo=python&logoColor=white)
![Pydantic](https://img.shields.io/badge/Pydantic-V2-E92063?style=for-the-badge&logo=pydantic&logoColor=white)

### 📊 Project Stats

![GitHub Actions](https://img.shields.io/badge/CI%2FCD-Passing-brightgreen?style=for-the-badge&logo=githubactions&logoColor=white)
![Tests](https://img.shields.io/badge/Tests-Passing-brightgreen?style=for-the-badge&logo=pytest&logoColor=white)
![Coverage](https://img.shields.io/badge/Coverage-TBD-yellow?style=for-the-badge&logo=codecov&logoColor=white)
![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge&logo=opensourceinitiative&logoColor=white)

### 🔧 Code Quality

![Ruff](https://img.shields.io/badge/Linter-Ruff-FCC21B?style=for-the-badge&logo=ruff&logoColor=black)
![MyPy](https://img.shields.io/badge/Type%20Checker-MyPy-blue?style=for-the-badge&logo=python&logoColor=white)
![Security](https://img.shields.io/badge/Security-Bandit-yellow?style=for-the-badge&logo=python&logoColor=white)
![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?style=for-the-badge&logo=pre-commit&logoColor=white)

### 🌟 Features

![Languages](https://img.shields.io/badge/Languages-38-4285F4?style=for-the-badge&logo=googletranslate&logoColor=white)
![Styles](https://img.shields.io/badge/Visual%20Styles-16-FF6B6B?style=for-the-badge&logo=adobe&logoColor=white)
![API](https://img.shields.io/badge/API-Async-00D084?style=for-the-badge&logo=fastapi&logoColor=white)
![Docker](https://img.shields.io/badge/Docker-Ready-2496ED?style=for-the-badge&logo=docker&logoColor=white)

**Transform text into stunning visuals with the power of AI** ✨

[🚀 Quick Start](#-quick-start) • [✨ Features](#-features) • [📚 Documentation](#-documentation) • [🎮 Demo](#-demo) • [🤝 Contributing](#-contributing)

</div>

---

## 🎯 What is Napkin AI API Playground?

A **production-ready** Python toolkit featuring both a **🌐 Streamlit web interface** and **💻 powerful CLI** that seamlessly transforms your text into professional-grade visuals using the Napkin AI API. Built with modern Python practices, robust error handling, intelligent retries, and comprehensive monitoring.

<div align="center">
<table>
<tr>
<td align="center">
<img src="https://img.shields.io/badge/Web%20App-Streamlit-FF4B4B?style=flat-square&logo=streamlit&logoColor=white" />
<br>Interactive Web UI
</td>
<td align="center">
<img src="https://img.shields.io/badge/CLI-Typer-4B8BBE?style=flat-square&logo=python&logoColor=white" />
<br>Command Line Tool
</td>
<td align="center">
<img src="https://img.shields.io/badge/API-Async-00D084?style=flat-square&logo=fastapi&logoColor=white" />
<br>Async Operations
</td>
<td align="center">
<img src="https://img.shields.io/badge/CI%2FCD-GitHub%20Actions-2088FF?style=flat-square&logo=githubactions&logoColor=white" />
<br>Automated Testing
</td>
</tr>
</table>
</div>

### 🎯 Perfect for:
- 📊 **Data Scientists** - Visualize complex concepts instantly
- 👩‍💻 **Developers** - Generate architecture diagrams from descriptions
- 📚 **Educators** - Create engaging visual content for teaching
- 💼 **Product Managers** - Quickly sketch out ideas and workflows
- 🎨 **Content Creators** - Transform text into beautiful graphics

## ✨ Features

<table>
<tr>
<td>

### 🌐 Streamlit Web Interface
- **Interactive UI** with real-time generation
- **Live preview** of all visual styles
- **Multi-language support** (38 languages)
- **Advanced options** panel
- **Download manager** for all formats
- **Mobile-responsive** design

</td>
<td>

### 💻 Powerful CLI
- **Full-featured** command line tool
- **Single visual generation**
- **JSON export** options
- **Rich terminal** output
- **Progress tracking** with spinners
- **Configuration management**

</td>
</tr>
<tr>
<td>

### 🎨 16 Visual Styles
- **Vibrant** - Bold, energetic visuals
- **Sketch** - Hand-drawn aesthetics
- **Corporate** - Professional graphics
- **Minimalist** - Clean, simple designs
- **Comic** - Fun, playful style
- **And many more!**

</td>
<td>

### ⚡ Advanced Features
- **Async API** with retry logic
- **Rate limiting** (60 req/min)
- **Error monitoring** dashboard
- **GitHub Actions** integration
- **Docker support**
- **Type-safe** with Pydantic v2

</td>
</tr>
</table>

## 🚀 Quick Start

### 📦 Installation

```bash
# Clone the repository
git clone https://github.com/moshehbenavraham/Napkin-AI-API.git
cd Napkin-AI-API

# Install with Poetry (recommended)
poetry install

# Or use pip
pip install -r requirements.txt
```

### 🔑 Configuration

```bash
# Copy example config
cp .env.example .env

# Add your API token (get one at https://napkin.ai)
echo "NAPKIN_API_TOKEN=your_token_here" >> .env

# Optional: Add GitHub token for error monitoring
echo "GITHUB_TOKEN=ghp_your_github_token" >> .env
```

### 🎮 Demo

#### 🌐 Web Interface (Streamlit)

```bash
# Launch the web app
poetry run streamlit run streamlit_app.py

# Or with custom port
poetry run streamlit run streamlit_app.py --server.port 8080

# Access at http://localhost:8501
```

<details>
<summary>📸 <b>Web Interface Screenshots</b></summary>

- Main generation interface
- Style browser with categories
- Multi-language support
- Advanced options panel
- Real-time generation
- Download manager

</details>

#### 💻 Command Line Interface

```bash
# Generate your first visual
poetry run napkin generate "Machine Learning Pipeline"

# With specific style and format
poetry run napkin generate "Data Flow" --style sketch-notes --format png

# Multiple variations
poetry run napkin generate "System Architecture" --variations 4

# Export to JSON
poetry run napkin generate "Workflow" --json output.json
```

## 🛠️ Advanced Usage

### 🌍 Multi-Language Support

Generate visuals in 38 languages using BCP 47 language tags:

```bash
# Spanish
napkin generate "Flujo de datos" --language es-ES

# Japanese
napkin generate "データフロー" --language ja-JP

# Arabic
napkin generate "تدفق البيانات" --language ar
```

### 🎯 Context Options

Add context for more meaningful visuals:

```bash
napkin generate "Neural Network" \
  --context-before "Introduction to" \
  --context-after "for beginners"
```

### 🔄 Visual Regeneration

Update existing visuals or search for specific types:

```bash
# Regenerate existing visual
napkin generate "Updated Content" --visual-id "5UCQJLAV5S6NXEWS2PBJF54UYPW5NZ4G"

# Search for specific visual type
napkin generate "Project Timeline" --visual-query "timeline"
```

### 📐 Custom Dimensions

For PNG format with specific dimensions:

```bash
napkin generate "Architecture" \
  --format png \
  --width 1920 \
  --height 1080 \
  --transparent \
  --inverted-color
```

## 🔍 CI/CD & Monitoring

### 📊 GitHub Actions Integration

Our project uses GitHub Actions for continuous integration with automated testing, linting, and deployment:

- **Python 3.10, 3.11, 3.12** matrix testing
- **Automated linting** with Ruff
- **Type checking** with MyPy
- **Security scanning** with Bandit
- **Coverage reporting** with Codecov
- **Automated notifications** on failure

### 🛠️ Built-in Monitoring Tool

Monitor your CI/CD pipeline with the unified `gh-monitor` tool:

```bash
# Monitor recent failures
bin/gh-monitor          # Show last 5 failures
bin/gh-monitor 10       # Show last 10 failures

# Analyze failures in detail
bin/gh-monitor analyze  # Detailed analysis with error messages

# Generate CI error reports
bin/gh-monitor report   # JSON report with context

# Export and format options
bin/gh-monitor 20 --json failures.json  # Export to JSON
bin/gh-monitor 10 --simple              # Simple one-line format
```

### 🔔 Automated Notifications

Configure automatic notifications for CI/CD failures:

<table>
<tr>
<td>

**Slack Integration**
```yaml
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
```

</td>
<td>

**Discord Integration**
```yaml
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
```

</td>
</tr>
<tr>
<td>

**Email Alerts**
```yaml
EMAIL_USERNAME: ${{ secrets.EMAIL_USERNAME }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
```

</td>
<td>

**GitHub Issues**
```yaml
CREATE_GITHUB_ISSUE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

</td>
</tr>
</table>

## 📚 Documentation

| Document | Description | Badge |
|----------|-------------|-------|
| 📘 [API Guide](docs/API_GUIDE.md) | Complete API reference & usage | ![API](https://img.shields.io/badge/API-Guide-blue?style=flat-square) |
| 📗 [Project Guide](docs/PROJECT_GUIDE.md) | Development, testing & contributing | ![Project](https://img.shields.io/badge/Project-Guide-green?style=flat-square) |
| 📙 [Official API Docs](docs/napkin_official/NAPKIN_AI_API.md) | Napkin's official API documentation | ![Official](https://img.shields.io/badge/Official-Docs-orange?style=flat-square) |

## 🏗️ Architecture

```mermaid
graph TD
    A[🌐 Web UI / 💻 CLI] -->|Streamlit / Typer| B[⚙️ Core Generator]
    B --> C[🔌 API Client]
    C -->|httpx + tenacity| D[☁️ Napkin API]
    B --> E[📋 Pydantic Models]
    E --> F[✅ Type Validation]
    B --> G[🔍 Error Monitor]
    G --> H[📊 GitHub Actions]
    
    style A fill:#FF4B4B,stroke:#333,stroke-width:2px
    style D fill:#4285F4,stroke:#333,stroke-width:2px
    style H fill:#2088FF,stroke:#333,stroke-width:2px
```

<details>
<summary><b>📁 Project Structure</b></summary>

```
napkin-api-playground/
├── 📱 streamlit_app.py     # Web interface (650 lines)
├── 🚀 main.py              # CLI entry point
├── 🔧 bin/
│   └── gh-monitor          # GitHub Actions monitoring tool
├── 📁 src/
│   ├── 🔌 api/            # Async API client & models
│   ├── 💻 cli/            # CLI commands & display
│   ├── ⚙️ core/           # Generation orchestration
│   └── 🔧 utils/          # Config & helpers
├── 🧪 tests/              # Test suite
├── 📚 docs/               # Complete documentation
├── 🔍 scripts/            # Monitoring & utilities
└── 🎨 data/               # Generated visuals
```

</details>

## 🧪 Development

### 🔬 Testing & Quality

```bash
# Run all tests
poetry run pytest

# With coverage report
poetry run pytest --cov=src --cov-report=html

# Type checking
poetry run mypy src/

# Linting
poetry run ruff check src/

# Security scan
poetry run bandit -r src/
```

### 🔍 GitHub Actions Monitoring

Monitor and analyze CI/CD failures with the unified monitoring tool:

```bash
# Show recent failures
bin/gh-monitor        # Last 5 failures
bin/gh-monitor 10     # Last 10 failures

# Analyze failures in detail
bin/gh-monitor analyze

# Generate CI error report
bin/gh-monitor report

# Export to JSON
bin/gh-monitor 5 --json failures.json

# Simple one-line format
bin/gh-monitor 10 --simple

# See all options
bin/gh-monitor --help
```

📚 [Full documentation](docs/GH_MONITOR.md)

### 📊 Code Quality Metrics

<div align="center">
<table>
<tr>
<td align="center">
<b>Tests</b><br>
<img src="https://img.shields.io/badge/passing-brightgreen?style=flat-square" />
</td>
<td align="center">
<b>Coverage</b><br>
<img src="https://img.shields.io/badge/TBD-yellow?style=flat-square" />
</td>
<td align="center">
<b>Type Safety</b><br>
<img src="https://img.shields.io/badge/MyPy-strict-blue?style=flat-square" />
</td>
<td align="center">
<b>Linting</b><br>
<img src="https://img.shields.io/badge/Ruff-clean-green?style=flat-square" />
</td>
<td align="center">
<b>Security</b><br>
<img src="https://img.shields.io/badge/Bandit-passed-yellow?style=flat-square" />
</td>
</tr>
</table>
</div>

## 🌟 What's New in v0.3.2

### ✨ Latest Features
- ✅ **Production-ready** status with all tests passing
- ✅ **Unified error monitoring** system
- ✅ **Enhanced CI/CD** with automatic notifications
- ✅ **Improved documentation** with badges
- ✅ **Fixed all deprecation** warnings
- ✅ **Python 3.10+** compatibility

### 🎨 Web Interface (v0.3.0)
- 🌍 **38 languages** with BCP 47 tags
- 📋 **Context options** for better visuals
- 🎯 **Advanced settings** panel
- 🔄 **Visual regeneration** feature
- 🔍 **Visual type search**
- 📱 **Mobile-responsive** design

## 🤝 Contributing

We love contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

<div align="center">
<table>
<tr>
<td align="center">
<img src="https://img.shields.io/badge/PRs-Welcome-brightgreen?style=for-the-badge" />
</td>
<td align="center">
<img src="https://img.shields.io/badge/Issues-Welcome-blue?style=for-the-badge" />
</td>
<td align="center">
<img src="https://img.shields.io/badge/Questions-Welcome-purple?style=for-the-badge" />
</td>
</tr>
</table>
</div>

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## 📊 Project Roadmap

### ✅ Completed Phases

<details>
<summary>✅ <b>Phase 1: Core MVP</b></summary>

- [x] Core API integration
- [x] CLI with all parameters
- [x] 16 styles support
- [x] Async operations
- [x] Comprehensive testing

</details>

<details>
<summary>✅ <b>Phase 2: Web Interface</b></summary>

- [x] Streamlit web application
- [x] Interactive style browser
- [x] Real-time generation
- [x] Download functionality
- [x] Multi-language support
- [x] Advanced options panel

</details>


### 🚧 Upcoming Features

- [ ] **Phase 3: Batch Processing** - Process multiple visuals from CSV/JSON
- [ ] **Phase 4: Gallery Mode** - Local SQLite gallery with search
- [ ] **Phase 5: Custom Styles** - Create and save custom visual styles
- [ ] **Team Collaboration** - Share visuals with team members
- [ ] **Cloud Integration** - S3/GCS storage support
- [ ] **API Webhooks** - Real-time generation notifications

## 🔒 Security

<div align="center">
<table>
<tr>
<td align="center">🔐 Tokens Never Logged</td>
<td align="center">🛡️ .env Gitignored</td>
<td align="center">✅ Input Validation</td>
</tr>
<tr>
<td align="center">🔄 HTTPS Only</td>
<td align="center">🔑 Bearer Auth</td>
<td align="center">🌐 Secure Headers</td>
</tr>
</table>
</div>

See [SECURITY.md](docs/SECURITY.md) for full security practices.

## 🐛 Troubleshooting

<details>
<summary>💻 <b>CLI Issues</b></summary>

| Issue | Solution |
|-------|----------|
| Rate limit errors | Client auto-retries with backoff (60 req/min limit) |
| File not found | Ensure output directory exists or use default `./data/visuals` |
| Token errors | Check `NAPKIN_API_TOKEN` in `.env` file |

</details>

<details>
<summary>🌐 <b>Web Interface Issues</b></summary>

| Issue | Solution |
|-------|----------|
| 403 Forbidden | Update to latest version (fixed in v0.2.1) |
| Pydantic errors | Update to latest version (fixed in v0.2.2) |
| Auth header required | Ensure API token is set correctly |

</details>

<details>
<summary>🔧 <b>Development Issues</b></summary>

| Issue | Solution |
|-------|----------|
| Poetry lock errors | Run `poetry lock` to update |
| Type check failures | Run `poetry run mypy src/` |
| Test failures | Ensure `.env` has valid token |

</details>

## 📄 License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

## 🙏 Acknowledgments

<div align="center">
<table>
<tr>
<td align="center">
<img src="https://img.shields.io/badge/Powered%20by-Napkin%20AI-FF6B6B?style=for-the-badge" /><br>
<a href="https://napkin.ai">Napkin AI API</a>
</td>
<td align="center">
<img src="https://img.shields.io/badge/Built%20with-Poetry-60A5FA?style=for-the-badge" /><br>
<a href="https://python-poetry.org/">Poetry</a>
</td>
</tr>
<tr>
<td align="center">
<img src="https://img.shields.io/badge/UI%20with-Streamlit-FF4B4B?style=for-the-badge" /><br>
<a href="https://streamlit.io">Streamlit</a>
</td>
<td align="center">
<img src="https://img.shields.io/badge/CLI%20with-Typer-4B8BBE?style=for-the-badge" /><br>
<a href="https://typer.tiangolo.com/">Typer</a>
</td>
</tr>
</table>
</div>

## 📞 Support

<div align="center">
<table>
<tr>
<td align="center">
📧 <b>Email</b><br>
<a href="mailto:api@napkin.ai">api@napkin.ai</a>
</td>
<td align="center">
🐛 <b>Issues</b><br>
<a href="https://github.com/moshehbenavraham/Napkin-AI-API/issues">GitHub Issues</a>
</td>
<td align="center">
💬 <b>Discussions</b><br>
<a href="https://github.com/moshehbenavraham/Napkin-AI-API/discussions">GitHub Discussions</a>
</td>
</tr>
</table>
</div>

---

<div align="center">

### 🌟 Star us on GitHub!

If you find this project useful, please consider giving it a star ⭐

![Stars](https://img.shields.io/github/stars/moshehbenavraham/Napkin-AI-API?style=social)
![Forks](https://img.shields.io/github/forks/moshehbenavraham/Napkin-AI-API?style=social)
![Watchers](https://img.shields.io/github/watchers/moshehbenavraham/Napkin-AI-API?style=social)

**Made with 🎨 and Python by the Napkin AI Community**

[⬆ Back to top](#-napkin-ai-api-playground)

</div>