Model Configuration Simplification
2025-06-0412 turns28,465 charsgpt-4-1-mini, gpt-4o, o4-mini⑂ 1 fork(s)
Summary
User simplified LLM model configuration for an automated news digest Python script and requested documentation updates.
Messages
I want to be able to change out the models for the LLM calls easily, put those variables at the beginning for easy editing: import os
import yaml
import feedparser
from newspaper import Article
from datetime import datetime
import asyncio
import edge_tts
import ollama
from tqdm import tqdm # Progress bar
# Load feed URLs from YAML configuration
def load_feeds(config_path='feeds.yaml'):
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
return config.get('feeds', [])
# Fetch and parse articles from RSS feeds
def fetch_articles(feed_urls, max_articles=1):
articles = []
print("Fetching and parsing RSS feeds...\n")
for url in tqdm(feed_urls, desc="Scraping feeds", unit="feed"):
feed = feedparser.parse(url)
for entry in feed.entries[:max_articles]:
articles.append({
'title': entry.title,
'link': entry.link,
'published': entry.get('published', 'N/A')
})
return articles
# Use Ollama to summarize text
def summarize_with_ollama(text, model='mistral:latest'):
prompt = (
"Summarize the following news article in 3-5 sentences, focusing on the key facts, context, "
"and implications. Avoid speculation and opinion.\n\n"
f"{text}\n\nSummary:"
)
response = ollama.chat(model=model, messages=[{"role": "user", "content": prompt}])
return response['message']['content']
# Extract and summarize article content using Ollama
def summarize_articles(articles, model='mistral:latest'):
summaries = []
print("\nSummarizing articles...\n")
for article in tqdm(articles, desc="Summarizing", unit="article"):
try:
news_article = Article(article['link'])
news_article.download()
news_article.parse()
text = news_article.text[:2000]
summary = summarize_with_ollama(text, model=model)
summaries.append({
'title': article['title'],
'link': article['link'],
'published': article['published'],
'summary': summary
})
except Exception as e:
print(f"Error processing article: {article['link']}\n{e}")
return summaries
# Use Ollama to generate a cohesive news broadcast from all summaries
def generate_broadcast(summaries, model='mistral-small:24b-instruct-2501-q8_0'):
joined_summaries = "\n\n".join(
f"Title: {s['title']}\nSummary: {s['summary']}" for s in summaries
)
prompt = (
"You are a professional news anchor. Create a coherent news broadcast script based on the following article summaries. "
"Weave them together into a flowing narrative, grouping related topics and keeping it informative and neutral:\n\n"
f"{joined_summaries}\n\nBroadcast:"
)
response = ollama.chat(model=model, messages=[{"role": "user", "content": prompt}])
return response['message']['content']
# Save full broadcast with timestamped filename
def save_digest(digest_text, output_dir='.'):
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
filename = os.path.join(output_dir, f'digest_{timestamp}.md')
with open(filename, 'w') as file:
file.write(digest_text)
return filename # return path for TTS to use
# Convert broadcast to speech with timestamped filename
async def text_to_speech(text, output_path, voice="en-US-GuyNeural"):
communicate = edge_tts.Communicate(text, voice=voice)
await communicate.save(output_path)
# Main workflow
def main():
feed_urls = load_feeds()
articles = fetch_articles(feed_urls, max_articles=1)
summaries = summarize_articles(articles, model='mistral:latest')
broadcast = generate_broadcast(summaries, model='mistral-small:24b-instruct-2501-q8_0')
# Save digest and get timestamped filename
digest_path = save_digest(broadcast)
# Create matching timestamped mp3 path
mp3_path = digest_path.replace('.md', '.mp3')
asyncio.run(text_to_speech(broadcast, output_path=mp3_path))
if __name__ == "__main__":
main()
You can make model swapping much easier by defining your model names at the top of the script as constants. Here's a clean way to do it:
---
### ✅ **Updated Code with Configurable Model Variables at the Top**
```python
# === CONFIGURABLE MODELS ===
SUMMARY_MODEL = 'mistral:latest'
BROADCAST_MODEL = 'mistral-small:24b-instruct-2501-q8_0'
TTS_VOICE = "en-US-GuyNeural" # Change voice if desired
# ===========================
import os
import yaml
import feedparser
from newspaper import Article
from datetime import datetime
import asyncio
import edge_tts
import ollama
from tqdm import tqdm # Progress bar
# Load feed URLs from YAML configuration
def load_feeds(config_path='feeds.yaml'):
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
return config.get('feeds', [])
# Fetch and parse articles from RSS feeds
def fetch_articles(feed_urls, max_articles=1):
articles = []
print("Fetching and parsing RSS feeds...\n")
for url in tqdm(feed_urls, desc="Scraping feeds", unit="feed"):
feed = feedparser.parse(url)
for entry in feed.entries[:max_articles]:
articles.append({
'title': entry.title,
'link': entry.link,
'published': entry.get('published', 'N/A')
})
return articles
# Use Ollama to summarize text
def summarize_with_ollama(text, model=SUMMARY_MODEL):
prompt = (
"Summarize the following news article in 3-5 sentences, focusing on the key facts, context, "
"and implications. Avoid speculation and opinion.\n\n"
f"{text}\n\nSummary:"
)
response = ollama.chat(model=model, messages=[{"role": "user", "content": prompt}])
return response['message']['content']
# Extract and summarize article content using Ollama
def summarize_articles(articles, model=SUMMARY_MODEL):
summaries = []
print("\nSummarizing articles...\n")
for article in tqdm(articles, desc="Summarizing", unit="article"):
try:
news_article = Article(article['link'])
news_article.download()
news_article.parse()
text = news_article.text[:2000]
summary = summarize_with_ollama(text, model=model)
summaries.append({
'title': article['title'],
'link': article['link'],
'published': article['published'],
'summary': summary
})
except Exception as e:
print(f"Error processing article: {article['link']}\n{e}")
return summaries
# Use Ollama to generate a cohesive news broadcast from all summaries
def generate_broadcast(summaries, model=BROADCAST_MODEL):
joined_summaries = "\n\n".join(
f"Title: {s['title']}\nSummary: {s['summary']}" for s in summaries
)
prompt = (
"You are a professional news anchor. Create a coherent news broadcast script based on the following article summaries. "
"Weave them together into a flowing narrative, grouping related topics and keeping it informative and neutral:\n\n"
f"{joined_summaries}\n\nBroadcast:"
)
response = ollama.chat(model=model, messages=[{"role": "user", "content": prompt}])
return response['message']['content']
# Save full broadcast with timestamped filename
def save_digest(digest_text, output_dir='.'):
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
filename = os.path.join(output_dir, f'digest_{timestamp}.md')
with open(filename, 'w') as file:
file.write(digest_text)
return filename # return path for TTS to use
# Convert broadcast to speech with timestamped filename
async def text_to_speech(text, output_path, voice=TTS_VOICE):
communicate = edge_tts.Communicate(text, voice=voice)
await communicate.save(output_path)
# Main workflow
def main():
feed_urls = load_feeds()
articles = fetch_articles(feed_urls, max_articles=1)
summaries = summarize_articles(articles)
broadcast = generate_broadcast(summaries)
# Save digest and get timestamped filename
digest_path = save_digest(broadcast)
# Create matching timestamped mp3 path
mp3_path = digest_path.replace('.md', '.mp3')
asyncio.run(text_to_speech(broadcast, output_path=mp3_path))
if __name__ == "__main__":
main()
```
---
### ✅ Benefits:
- Easy to update models by changing just the top few lines.
- Makes testing different model variants quick and clean.
- Prepares your codebase for possible config file loading later (e.g. from YAML or `.env`).
Let me know if you want to move those config values to a YAML or `.env` file instead.
gpt-4o
is this the correct requirements.txt, if not edit it: feedparser
newspaper3k
transformers
torch
pyyaml
edge-tts
lxml[html_clean]
ollama
asyncio
tdqm
You're very close! Just a few small corrections and improvements:
---
### ✅ **Corrected `requirements.txt`:**
```txt
feedparser
newspaper3k
transformers
torch
pyyaml
edge-tts
lxml[html_clean]
ollama
tqdm
```
---
### ⚠️ Notes:
- `tdqm` → should be `tqdm` (just a typo).
- `asyncio` is part of the Python standard library, so **it doesn't need to be listed** in `requirements.txt`.
- You might also consider pinning versions if you're deploying or sharing with others, e.g.:
```txt
feedparser==6.0.10
newspaper3k==0.2.8
...
```
Would you like a version-pinned version of this for reproducibility or Docker setup?
gpt-4o
now write a readme.md for : # === CONFIGURABLE MODELS ===
SUMMARY_MODEL = 'mistral:latest'
BROADCAST_MODEL = 'mistral-small:24b-instruct-2501-q8_0'
TTS_VOICE = "en-US-GuyNeural" # Change voice if desired
# ===========================
import os
import yaml
import feedparser
from newspaper import Article
from datetime import datetime
import asyncio
import edge_tts
import ollama
from tqdm import tqdm # Progress bar
# Load feed URLs from YAML configuration
def load_feeds(config_path='feeds.yaml'):
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
return config.get('feeds', [])
# Fetch and parse articles from RSS feeds
def fetch_articles(feed_urls, max_articles=1):
articles = []
print("Fetching and parsing RSS feeds...\n")
for url in tqdm(feed_urls, desc="Scraping feeds", unit="feed"):
feed = feedparser.parse(url)
for entry in feed.entries[:max_articles]:
articles.append({
'title': entry.title,
'link': entry.link,
'published': entry.get('published', 'N/A')
})
return articles
# Use Ollama to summarize text
def summarize_with_ollama(text, model=SUMMARY_MODEL):
prompt = (
"Summarize the following news article in 3-5 sentences, focusing on the key facts, context, "
"and implications. Avoid speculation and opinion.\n\n"
f"{text}\n\nSummary:"
)
response = ollama.chat(model=model, messages=[{"role": "user", "content": prompt}])
return response['message']['content']
# Extract and summarize article content using Ollama
def summarize_articles(articles, model=SUMMARY_MODEL):
summaries = []
print("\nSummarizing articles...\n")
for article in tqdm(articles, desc="Summarizing", unit="article"):
try:
news_article = Article(article['link'])
news_article.download()
news_article.parse()
text = news_article.text[:2000]
summary = summarize_with_ollama(text, model=model)
summaries.append({
'title': article['title'],
'link': article['link'],
'published': article['published'],
'summary': summary
})
except Exception as e:
print(f"Error processing article: {article['link']}\n{e}")
return summaries
# Use Ollama to generate a cohesive news broadcast from all summaries
def generate_broadcast(summaries, model=BROADCAST_MODEL):
joined_summaries = "\n\n".join(
f"Title: {s['title']}\nSummary: {s['summary']}" for s in summaries
)
prompt = (
"You are a professional news anchor. Create a coherent news broadcast script based on the following article summaries. "
"Weave them together into a flowing narrative, grouping related topics and keeping it informative and neutral:\n\n"
f"{joined_summaries}\n\nBroadcast:"
)
response = ollama.chat(model=model, messages=[{"role": "user", "content": prompt}])
return response['message']['content']
# Save full broadcast with timestamped filename
def save_digest(digest_text, output_dir='.'):
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
filename = os.path.join(output_dir, f'digest_{timestamp}.md')
with open(filename, 'w') as file:
file.write(digest_text)
return filename # return path for TTS to use
# Convert broadcast to speech with timestamped filename
async def text_to_speech(text, output_path, voice=TTS_VOICE):
communicate = edge_tts.Communicate(text, voice=voice)
await communicate.save(output_path)
# Main workflow
def main():
feed_urls = load_feeds()
articles = fetch_articles(feed_urls, max_articles=1)
summaries = summarize_articles(articles)
broadcast = generate_broadcast(summaries)
# Save digest and get timestamped filename
digest_path = save_digest(broadcast)
# Create matching timestamped mp3 path
mp3_path = digest_path.replace('.md', '.mp3')
asyncio.run(text_to_speech(broadcast, output_path=mp3_path))
if __name__ == "__main__":
main()
Here’s a complete `README.md` for your project:
---
```markdown
# 📰 AI News Digest Generator
This Python script automatically fetches news articles from RSS feeds, summarizes them using a local LLM (via Ollama), writes a coherent broadcast-style script, and generates a text-to-speech (TTS) audio file of the broadcast.
## ✨ Features
- Pulls articles from any RSS feed (configurable via `feeds.yaml`)
- Summarizes news using a local LLM (Ollama)
- Generates a flowing, anchor-style news script
- Converts the script into an MP3 audio broadcast using Microsoft Edge TTS
- Saves both text and audio versions with timestamped filenames
---
## 🔧 Configurable Models
You can easily modify which models or voices to use by changing these variables at the top of the script:
```python
# === CONFIGURABLE MODELS ===
SUMMARY_MODEL = 'mistral:latest' # For summarizing articles
BROADCAST_MODEL = 'mistral-small:24b-instruct-2501-q8_0' # For combining summaries into a narrative
TTS_VOICE = "en-US-GuyNeural" # Microsoft Edge TTS voice
```
---
## 📦 Installation
1. **Clone this repository:**
```bash
git clone https://github.com/yourusername/news-digest-ai.git
cd news-digest-ai
```
2. **Install dependencies:**
Make sure you have Python 3.8+ and install the required packages:
```bash
pip install -r requirements.txt
```
3. **Install Ollama** (if not already):
- Follow setup instructions at [https://ollama.com](https://ollama.com)
---
## 📄 feeds.yaml Example
Create a file called `feeds.yaml` in the project root:
```yaml
feeds:
- https://rss.nytimes.com/services/xml/rss/nyt/World.xml
- https://feeds.bbci.co.uk/news/rss.xml
```
---
## 🚀 Running the Script
```bash
python your_script_name.py
```
The script will:
- Fetch one article per feed
- Summarize each
- Generate a full news digest
- Save the digest as `digest_YYYY-MM-DD_HH-MM-SS.md`
- Save an audio file as `digest_YYYY-MM-DD_HH-MM-SS.mp3`
---
## 🗣️ Voice Options
You can change the voice used for TTS by editing the `TTS_VOICE` variable. Supported voices include:
- `"en-US-GuyNeural"` (default, male)
- `"en-US-JennyNeural"` (female)
- `"en-GB-RyanNeural"` (UK male)
- `"en-IN-PrabhatNeural"` (Indian English male)
See [Edge TTS Voice List](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support#text-to-speech) for more.
---
## 🧠 Customization Tips
- Adjust `max_articles` in `fetch_articles()` to increase number of articles per feed.
- Modify the `summarize_with_ollama()` and `generate_broadcast()` prompts for different tone or depth.
- Swap `SUMMARY_MODEL` or `BROADCAST_MODEL` to use other Ollama-supported models like `llama3`, `gemma`, etc.
---
## 📁 Output
- Markdown news summary file
- Matching MP3 file with TTS narration
Files are saved in the same directory by default. You can change `output_dir` in `save_digest()`.
---
## 🔒 License
MIT License
---
## 🤝 Contributing
PRs welcome! If you have ideas for new features (like sentiment filters, daily scheduling, or multiple language support), feel free to open an issue or submit a pull request.
```
---
Let me know if you want this turned into a `mkdocs` or `README.html` version for fancy hosting/documentation.
gpt-4o
⑂ thread forked here
format this as a .md: # 📰 AI News Digest Generator
This Python script automatically fetches news articles from RSS feeds, summarizes them using a local LLM (via Ollama), writes a coherent broadcast-style script, and generates a text-to-speech (TTS) audio file of the broadcast.
## ✨ Features
- Pulls articles from any RSS feed (configurable via `feeds.yaml`)
- Summarizes news using a local LLM (Ollama)
- Generates a flowing, anchor-style news script
- Converts the script into an MP3 audio broadcast using Microsoft Edge TTS
- Saves both text and audio versions with timestamped filenames
---
## 🔧 Configurable Models
You can easily modify which models or voices to use by changing these variables at the top of the script:
```python
# === CONFIGURABLE MODELS ===
SUMMARY_MODEL = 'mistral:latest' # For summarizing articles
BROADCAST_MODEL = 'mistral-small:24b-instruct-2501-q8_0' # For combining summaries into a narrative
TTS_VOICE = "en-US-GuyNeural" # Microsoft Edge TTS voice
```
⸻
📦 Installation
1. Clone this repository:
```bash
git clone https://github.com/kliewerdaniel/news02.git
cd news02
```
2. Install dependencies:
Make sure you have Python 3.8+ and install the required packages:
```bash
pip install -r requirements.txt
```
3. Install Ollama (if not already):
• Follow setup instructions at https://ollama.com
⸻
📄 feeds.yaml Example
Create a file called feeds.yaml in the project root:
```yaml
feeds:
- https://rss.nytimes.com/services/xml/rss/nyt/World.xml
- https://feeds.bbci.co.uk/news/rss.xml
```
⸻
🚀 Running the Script
```bash
python your_script_name.py
```
The script will:
• Fetch one article per feed
• Summarize each
• Generate a full news digest
• Save the digest as digest_YYYY-MM-DD_HH-MM-SS.md
• Save an audio file as digest_YYYY-MM-DD_HH-MM-SS.mp3
⸻
🗣️ Voice Options
You can change the voice used for TTS by editing the TTS_VOICE variable. Supported voices include:
• "en-US-GuyNeural" (default, male)
• "en-US-JennyNeural" (female)
• "en-GB-RyanNeural" (UK male)
• "en-IN-PrabhatNeural" (Indian English male)
See Edge TTS Voice List for more.
⸻
🧠 Customization Tips
• Adjust max_articles in fetch_articles() to increase number of articles per feed.
• Modify the summarize_with_ollama() and generate_broadcast() prompts for different tone or depth.
• Swap SUMMARY_MODEL or BROADCAST_MODEL to use other Ollama-supported models like llama3, gemma, etc.
⸻
📁 Output
• Markdown news summary file
• Matching MP3 file with TTS narration
Files are saved in the same directory by default. You can change output_dir in save_digest().
⸻
🔒 License
MIT License
⸻
Here's your formatted `README.md` in proper Markdown:
```markdown
# 📰 AI News Digest Generator
This Python script automatically fetches news articles from RSS feeds, summarizes them using a local LLM (via Ollama), writes a coherent broadcast-style script, and generates a text-to-speech (TTS) audio file of the broadcast.
---
## ✨ Features
- Pulls articles from any RSS feed (configurable via `feeds.yaml`)
- Summarizes news using a local LLM (Ollama)
- Generates a flowing, anchor-style news script
- Converts the script into an MP3 audio broadcast using Microsoft Edge TTS
- Saves both text and audio versions with timestamped filenames
---
## 🔧 Configurable Models
You can easily modify which models or voices to use by changing these variables at the top of the script:
```python
# === CONFIGURABLE MODELS ===
SUMMARY_MODEL = 'mistral:latest' # For summarizing articles
BROADCAST_MODEL = 'mistral-small:24b-instruct-2501-q8_0' # For combining summaries into a narrative
TTS_VOICE = "en-US-GuyNeural" # Microsoft Edge TTS voice
```
---
## 📦 Installation
1. **Clone this repository:**
```bash
git clone https://github.com/kliewerdaniel/news02.git
cd news02
```
2. **Install dependencies:**
Make sure you have Python 3.8+ and install the required packages:
```bash
pip install -r requirements.txt
```
3. **Install Ollama (if not already):**
Follow setup instructions at [https://ollama.com](https://ollama.com)
---
## 📄 feeds.yaml Example
Create a file called `feeds.yaml` in the project root:
```yaml
feeds:
- https://rss.nytimes.com/services/xml/rss/nyt/World.xml
- https://feeds.bbci.co.uk/news/rss.xml
```
---
## 🚀 Running the Script
```bash
python your_script_name.py
```
The script will:
- Fetch one article per feed
- Summarize each
- Generate a full news digest
- Save the digest as `digest_YYYY-MM-DD_HH-MM-SS.md`
- Save an audio file as `digest_YYYY-MM-DD_HH-MM-SS.mp3`
---
## 🗣️ Voice Options
You can change the voice used for TTS by editing the `TTS_VOICE` variable. Supported voices include:
- `"en-US-GuyNeural"` (default, male)
- `"en-US-JennyNeural"` (female)
- `"en-GB-RyanNeural"` (UK male)
- `"en-IN-PrabhatNeural"` (Indian English male)
See [Edge TTS Voice List](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support#text-to-speech) for more.
---
## 🧠 Customization Tips
- Adjust `max_articles` in `fetch_articles()` to increase number of articles per feed.
- Modify the `summarize_with_ollama()` and `generate_broadcast()` prompts for different tone or depth.
- Swap `SUMMARY_MODEL` or `BROADCAST_MODEL` to use other Ollama-supported models like `llama3`, `gemma`, etc.
---
## 📁 Output
- Markdown news summary file
- Matching MP3 file with TTS narration
Files are saved in the same directory by default. You can change `output_dir` in `save_digest()`.
---
## 🔒 License
MIT License
---
```
Let me know if you want this version written into a `README.md` file directly or converted into HTML for a web page.
gpt-4o
Here's your README content properly formatted as Markdown (`.md`):
```md
# 📰 AI News Digest Generator
This Python script automatically fetches news articles from RSS feeds, summarizes them using a local LLM (via Ollama), writes a coherent broadcast-style script, and generates a text-to-speech (TTS) audio file of the broadcast.
## ✨ Features
- Pulls articles from any RSS feed (configurable via `feeds.yaml`)
- Summarizes news using a local LLM (Ollama)
- Generates a flowing, anchor-style news script
- Converts the script into an MP3 audio broadcast using Microsoft Edge TTS
- Saves both text and audio versions with timestamped filenames
---
## 🔧 Configurable Models
You can easily modify which models or voices to use by changing these variables at the top of the script:
```python
# === CONFIGURABLE MODELS ===
SUMMARY_MODEL = 'mistral:latest' # For summarizing articles
BROADCAST_MODEL = 'mistral-small:24b-instruct-2501-q8_0' # For combining summaries into a narrative
TTS_VOICE = "en-US-GuyNeural" # Microsoft Edge TTS voice
```
---
## 📦 Installation
1. Clone this repository:
```bash
git clone https://github.com/kliewerdaniel/news02.git
cd news02
```
2. Install dependencies:
Make sure you have Python 3.8+ and install the required packages:
```bash
pip install -r requirements.txt
```
3. Install Ollama (if not already):
- Follow setup instructions at [https://ollama.com](https://ollama.com)
---
## 📄 feeds.yaml Example
Create a file called `feeds.yaml` in the project root:
```yaml
feeds:
- https://rss.nytimes.com/services/xml/rss/nyt/World.xml
- https://feeds.bbci.co.uk/news/rss.xml
```
---
## 🚀 Running the Script
```bash
python your_script_name.py
```
The script will:
- Fetch one article per feed
- Summarize each
- Generate a full news digest
- Save the digest as `digest_YYYY-MM-DD_HH-MM-SS.md`
- Save an audio file as `digest_YYYY-MM-DD_HH-MM-SS.mp3`
---
## 🗣️ Voice Options
You can change the voice used for TTS by editing the `TTS_VOICE` variable. Supported voices include:
- `"en-US-GuyNeural"` (default, male)
- `"en-US-JennyNeural"` (female)
- `"en-GB-RyanNeural"` (UK male)
- `"en-IN-PrabhatNeural"` (Indian English male)
See [Edge TTS Voice List](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support#text-to-speech) for more.
---
## 🧠 Customization Tips
- Adjust `max_articles` in `fetch_articles()` to increase number of articles per feed.
- Modify the `summarize_with_ollama()` and `generate_broadcast()` prompts for different tone or depth.
- Swap `SUMMARY_MODEL` or `BROADCAST_MODEL` to use other Ollama-supported models like `llama3`, `gemma`, etc.
---
## 📁 Output
- Markdown news summary file
- Matching MP3 file with TTS narration
Files are saved in the same directory by default. You can change `output_dir` in `save_digest()`.
---
## 🔒 License
MIT License
---
```
If you want me to generate a downloadable `.md` file or add anything else, just let me know!
gpt-4-1-mini
⚙ model reasoning step
o4-mini
⚙ model reasoning step
o4-mini
```markdown
# 📰 AI News Digest Generator
This Python script automatically fetches news articles from RSS feeds, summarizes them using a local LLM (via Ollama), writes a coherent broadcast-style script, and generates a text-to-speech (TTS) audio file of the broadcast.
## ✨ Features
- Pulls articles from any RSS feed (configurable via `feeds.yaml`)
- Summarizes news using a local LLM (Ollama)
- Generates a flowing, anchor-style news script
- Converts the script into an MP3 audio broadcast using Microsoft Edge TTS
- Saves both text and audio versions with timestamped filenames
---
## 🔧 Configurable Models
You can easily modify which models or voices to use by changing these variables at the top of the script:
```python
# === CONFIGURABLE MODELS ===
SUMMARY_MODEL = 'mistral:latest' # For summarizing articles
BROADCAST_MODEL = 'mistral-small:24b-instruct-2501-q8_0' # For combining summaries into a narrative
TTS_VOICE = "en-US-GuyNeural" # Microsoft Edge TTS voice
# ===========================
```
---
## 📦 Installation
1. **Clone this repository:**
```bash
git clone https://github.com/kliewerdaniel/news02.git
cd news02
```
2. **Install dependencies:**
Make sure you have Python 3.8+ and install the required packages:
```bash
pip install -r requirements.txt
```
3. **Install Ollama (if not already):**
Follow setup instructions at [https://ollama.com](https://ollama.com)
---
## 📄 `feeds.yaml` Example
Create a file called `feeds.yaml` in the project root:
```yaml
feeds:
- https://rss.nytimes.com/services/xml/rss/nyt/World.xml
- https://feeds.bbci.co.uk/news/rss.xml
```
---
## 🚀 Running the Script
```bash
python your_script_name.py
```
The script will:
- Fetch one article per feed
- Summarize each
- Generate a full news digest
- Save the digest as `digest_YYYY-MM-DD_HH-MM-SS.md`
- Save an audio file as `digest_YYYY-MM-DD_HH-MM-SS.mp3`
---
## 🗣️ Voice Options
You can change the voice used for TTS by editing the `TTS_VOICE` variable. Supported voices include:
- `en-US-GuyNeural` (default, male)
- `en-US-JennyNeural` (female)
- `en-GB-RyanNeural` (UK male)
- `en-IN-PrabhatNeural` (Indian English male)
See [Edge TTS Voice List](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support#text-to-speech) for more.
---
## 🧠 Customization Tips
- Adjust `max_articles` in `fetch_articles()` to increase the number of articles per feed.
- Modify the `summarize_with_ollama()` and `generate_broadcast()` prompts for a different tone or depth.
- Swap `SUMMARY_MODEL` or `BROADCAST_MODEL` to use other Ollama-supported models like `llama3`, `gemma`, etc.
---
## 📁 Output
- Markdown news summary file
- Matching MP3 file with TTS narration
Files are saved in the same directory by default. You can change `output_dir` in `save_digest()`.
---
## 🔒 License
MIT License
```
o4-mini