Spaces:
Sleeping
Sleeping
File size: 8,079 Bytes
fc18788 4024eae 9010fb4 4024eae | 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | ---
title: AI Newsletter Generator
emoji: π°
colorFrom: indigo
colorTo: purple
sdk: docker
app_file: app.py
pinned: false
---
# AI Newsletter Generator
A full-stack AI-powered newsletter generator that creates engaging newsletters from RSS feeds with intelligent article summarization, tweet generation, and AI-assisted editing.
## β¨ Features
- π€ **AI-Enhanced Article Summaries**: LLM-generated engaging abstracts for better readability
- π° **RSS Feed Aggregation**: Curate content from multiple AI/tech news sources
- π **Smart Article Selection**: Interactive interface to choose articles for processing
- π **Deep Article Summarization**: AI-powered detailed summaries of selected articles
- π¦ **Social Media Content**: Generate Twitter/X posts with AI editing capabilities
- π§ **Professional Newsletters**: Create polished HTML newsletters
- β¨ **Interactive AI Editing**: Real-time AI assistance for content refinement
- π¨ **Modern UI**: Beautiful React interface with gradient backgrounds and smooth interactions
- β‘ **Fast Performance**: Vite-powered frontend with hot reload
- π **Environment Security**: Secure API key management
## ποΈ Architecture
### Project Structure
```
AI-NewsLetter/
βββ backend/ # FastAPI backend
β βββ main.py # API endpoints + static file serving
βββ frontend/ # React + Vite + Tailwind frontend
β βββ src/
β β βββ components/ # React components
β β β βββ FeedPicker.tsx
β β β βββ TweetCards.tsx
β β β βββ EditorModal.tsx
β β βββ App.tsx # Main application
β β βββ index.css # Tailwind styles
β βββ dist/ # Built frontend (served by backend)
βββ pyproject.toml # Python dependencies (managed by uv)
βββ .env # Environment variables
βββ README.md
```
### Technology Stack
**Backend:**
- **FastAPI** - Modern Python web framework with automatic API docs
- **OpenAI API** - GPT-4o-mini for content generation and enhancement
- **httpx** - Async HTTP client for web scraping
- **feedparser** - RSS/Atom feed parsing
- **uvicorn** - High-performance ASGI server
**Frontend:**
- **React 19** - Latest React with modern hooks
- **TypeScript** - Type safety and better developer experience
- **Vite** - Lightning-fast build tool and dev server
- **Tailwind CSS v3** - Utility-first styling with custom components
- **pnpm** - Fast, disk-efficient package manager
**Development Tools:**
- **uv** - Ultra-fast Python package manager
- **ESLint** - Code linting and formatting
- **PostCSS** - CSS processing with Tailwind
## π Quick Start
### Prerequisites
- **Python 3.12+** with [uv](https://docs.astral.sh/uv/) installed
- **Node.js 18+**
- **pnpm** (recommended) or npm
- **OpenAI API Key** - Get one from [OpenAI Platform](https://platform.openai.com/account/api-keys)
### 1. Environment Setup
Create a `.env` file in the project root:
```bash
OPENAI_API_KEY=sk-your-actual-openai-api-key-here
```
### 2. Backend Setup
```bash
# Install Python dependencies
uv sync
# Start the FastAPI server (serves both API and frontend)
uv run uvicorn backend.main:app --host 127.0.0.1 --port 8000 --reload
```
### 3. Frontend Setup
```bash
cd frontend
# Install dependencies
pnpm install
# Build for production
pnpm build
```
### 4. Access the Application
Open your browser to **http://127.0.0.1:8000**
The backend serves both the API endpoints and the built React frontend from a single port.
## π User Guide
### Workflow
1. **Select Sources**: Choose from curated AI/tech RSS feeds
2. **Get Highlights**: Fetch articles and generate initial AI summary
3. **Select Articles**: Review articles with AI-enhanced abstracts
4. **Get Summaries**: Generate detailed summaries for selected articles (max 5)
5. **Generate Tweets**: Create social media content with AI editing
6. **Create Newsletter**: Build professional HTML newsletter
7. **Download**: Export your newsletter
### Key Features Explained
**AI-Enhanced Abstracts**: When you click "Get Highlights", the system not only fetches articles but uses GPT to create engaging 2-3 sentence summaries for each article, making them much more readable and compelling than raw RSS descriptions.
**Smart Article Selection**: The interface shows checkboxes for each article with enhanced summaries, publication dates, and sources. You can easily select which articles to dive deeper into.
**Detailed Summarization**: The "Get Summaries" feature scrapes full article content and creates comprehensive summaries using AI, perfect for busy readers who want key insights.
**Interactive AI Editing**: Both tweets and newsletter content can be edited with AI assistance through natural language commands.
## π§ Development
### Full-Stack Development (Recommended)
```bash
# Terminal 1: Start backend
uv run uvicorn backend.main:app --host 127.0.0.1 --port 8000 --reload
# Terminal 2: Build frontend after changes
cd frontend && pnpm build
```
### Frontend-Only Development
For rapid UI development with hot reload:
```bash
# Terminal 1: Backend
uv run uvicorn backend.main:app --host 127.0.0.1 --port 8000 --reload
# Terminal 2: Frontend dev server
cd frontend && pnpm dev --port 3002
```
Then open http://127.0.0.1:3002 for development or http://127.0.0.1:8000 for production.
### Available Scripts
**Backend:**
```bash
uv sync # Install dependencies
uv run uvicorn backend.main:app --reload # Start server
```
**Frontend:**
```bash
pnpm install # Install dependencies
pnpm build # Build for production
pnpm dev # Development server
pnpm type-check # TypeScript checking
pnpm clean # Clean build artifacts
```
## π API Reference
### Core Endpoints
- `GET /` - Serves React frontend application
- `GET /api/health` - API health check
- `GET /api/defaults` - Get default RSS feed sources
### Content Generation
- `POST /api/aggregate` - Fetch articles from RSS feeds with AI-enhanced summaries
- `POST /api/highlights` - Generate weekly highlights summary
- `POST /api/summaries_selected` - Create detailed summaries for selected articles
- `POST /api/tweets` - Generate social media posts from summaries
- `POST /api/newsletter` - Create HTML newsletter
- `POST /api/edit_tweet` - AI-powered tweet editing
### Example API Usage
```bash
# Get enhanced articles with AI summaries
curl -X POST "http://127.0.0.1:8000/api/aggregate" \
-H "Content-Type: application/json" \
-d '{"sources": ["https://huggingface.co/blog/feed.xml"]}'
# Generate detailed summaries
curl -X POST "http://127.0.0.1:8000/api/summaries_selected" \
-H "Content-Type: application/json" \
-d '{"articles": [...]}'
```
## π³ Deployment
### Hugging Face Spaces
This project includes a Dockerfile optimized for Hugging Face Spaces deployment:
1. Push your code to a Hugging Face repository
2. Set your `OPENAI_API_KEY` in the Space settings
3. The Dockerfile will handle the rest!
### Other Platforms
The application can be deployed on any platform that supports Docker containers:
- Railway
- Render
- DigitalOcean App Platform
- AWS ECS
- Google Cloud Run
## π€ Contributing
Contributions are welcome! This project uses:
- **Python**: Black formatting, type hints encouraged
- **TypeScript**: Strict mode, ESLint configuration
- **Git**: Conventional commit messages preferred
## π License
This project is open source and available under the MIT License.
## πββοΈ Support
Having issues?
1. Check that your OpenAI API key is correctly set in `.env`
2. Ensure all dependencies are installed (`uv sync` and `pnpm install`)
3. Verify the frontend is built (`pnpm build`) before accessing the full-stack app
---
Built with β€οΈ using modern web technologies and AI. |