Skip to content

vtavakkoli/GenWiki

Repository files navigation

GenWiki — DuckDuckGo + Ollama Wikipedia Generator

GenWiki is a small Flask web application that creates Wikipedia-style pages for any topic. It searches DuckDuckGo for source snippets and images, sends the collected context to a fixed Ollama model, and renders a clean article with citations, pictures, references, and internal See also links.

The model is fixed on the server side. Users cannot change it from the web UI or by adding a ?model=... parameter to the URL.

Screenshot

GenWiki app home page

Main features

  • DuckDuckGo text search for source snippets
  • DuckDuckGo image search with SafeSearch and unsafe-domain filtering
  • Ollama-based article generation
  • Wikipedia-like article layout
  • Source references and citation markers
  • Internal GenWiki See also links, for example /wiki?topic=Kubernetes
  • Debug and health pages for troubleshooting
  • Windows, Linux, and macOS runner scripts
  • Detailed logs in logs/genwiki.log

Requirements

  • Python 3.10 or newer
  • Ollama installed and running
  • Internet access for DuckDuckGo search and image results
  • An available Ollama model, for example:
ollama pull gemma4:31b-cloud

Start Ollama in a separate terminal if it is not already running:

ollama serve

Test Ollama quickly:

curl http://localhost:11434/api/generate -d '{"model":"gemma4:31b-cloud","prompt":"Reply only with OK.","stream":false}'

Fast start on Windows PowerShell

Open PowerShell in the project folder and run:

powershell -ExecutionPolicy Bypass -File .\run_windows.ps1

Then open:

http://127.0.0.1:5000

Fast start on Windows Command Prompt

Open cmd.exe in the project folder and run:

run_windows.bat

Then open:

http://127.0.0.1:5000

Fast start on Linux or macOS

Open a terminal in the project folder and run:

chmod +x run_linux.sh
./run_linux.sh

Then open:

http://127.0.0.1:5000

Fixed project settings

The runner scripts use these stable settings:

Variable Value Purpose
OLLAMA_HOST http://localhost:11434 Ollama server URL
GENWIKI_MODEL gemma4:31b-cloud Fixed server-side model
GENWIKI_REQUEST_TIMEOUT 300 Ollama timeout in seconds
GENWIKI_MAX_SOURCES 4 Number of DuckDuckGo text sources
GENWIKI_MAX_IMAGES 4 Number of images shown
GENWIKI_NUM_CTX 262144 Ollama context size
GENWIKI_NUM_PREDICT 650 Maximum generated output tokens
GENWIKI_STREAM 1 Use Ollama streaming responses
GENWIKI_SAFE_IMAGES 1 Filter unsafe image results
GENWIKI_REGION wt-wt DuckDuckGo search region
GENWIKI_LOG_LEVEL DEBUG Detailed logs
FLASK_DEBUG 1 Flask debug mode
PORT 5000 Local web server port

The web UI and URL parameters cannot change GENWIKI_MODEL. To change the model, edit the server-side runner script or .env file before starting the app.

Manual setup

Create and activate a virtual environment:

python -m venv .venv

Windows PowerShell:

.\.venv\Scripts\Activate.ps1

Windows Command Prompt:

.venv\Scripts\activate.bat

Linux/macOS:

source .venv/bin/activate

Install dependencies:

python -m pip install --upgrade pip
pip install -r requirements.txt

Set the environment variables and start the app:

Windows PowerShell:

$env:OLLAMA_HOST="http://localhost:11434"
$env:GENWIKI_MODEL="gemma4:31b-cloud"
$env:GENWIKI_REQUEST_TIMEOUT="300"
$env:GENWIKI_MAX_SOURCES="4"
$env:GENWIKI_MAX_IMAGES="4"
$env:GENWIKI_NUM_CTX="262144"
$env:GENWIKI_NUM_PREDICT="650"
$env:GENWIKI_STREAM="1"
$env:GENWIKI_SAFE_IMAGES="1"
$env:GENWIKI_REGION="wt-wt"
$env:GENWIKI_LOG_LEVEL="DEBUG"
$env:FLASK_DEBUG="1"
$env:PORT="5000"
python genwiki.py

Linux/macOS:

export OLLAMA_HOST="http://localhost:11434"
export GENWIKI_MODEL="gemma4:31b-cloud"
export GENWIKI_REQUEST_TIMEOUT="300"
export GENWIKI_MAX_SOURCES="4"
export GENWIKI_MAX_IMAGES="4"
export GENWIKI_NUM_CTX="262144"
export GENWIKI_NUM_PREDICT="650"
export GENWIKI_STREAM="1"
export GENWIKI_SAFE_IMAGES="1"
export GENWIKI_REGION="wt-wt"
export GENWIKI_LOG_LEVEL="DEBUG"
export FLASK_DEBUG="1"
export PORT="5000"
python genwiki.py

Optional .env file

You can copy .env.example to .env and edit it:

Windows PowerShell:

Copy-Item .env.example .env
python genwiki.py

Linux/macOS:

cp .env.example .env
python genwiki.py

The app loads .env automatically when it starts.

Useful pages

Main page:

http://127.0.0.1:5000

Generate a page directly:

http://127.0.0.1:5000/wiki?topic=OpenShift

Diagnostics page:

http://127.0.0.1:5000/debug

JSON health check:

http://127.0.0.1:5000/health

Logs

The app writes logs to:

logs/genwiki.log

Watch logs live on Windows PowerShell:

Get-Content .\logs\genwiki.log -Wait

Watch logs live on Linux/macOS:

tail -f logs/genwiki.log

Troubleshooting

The page shows a fallback summary instead of an Ollama article

Check the debug page first:

http://127.0.0.1:5000/debug

Then check the log file:

logs/genwiki.log

Common causes:

  • Ollama is not running.
  • The model is not available in Ollama.
  • The model takes longer than the configured timeout.
  • Another old Flask process is still using port 5000.
  • The computer does not have enough memory for the selected model/context size.

Stop an old Flask process on Windows

Get-Process python | Stop-Process

Then restart:

powershell -ExecutionPolicy Bypass -File .\run_windows.ps1

Stop an old Flask process on Linux/macOS

pkill -f genwiki.py

Then restart:

./run_linux.sh

Ollama is reachable with curl but GenWiki still times out

A short curl prompt may finish quickly, while GenWiki sends a longer prompt with source snippets, citations, and HTML instructions. Keep streaming enabled, keep source count small, and increase GENWIKI_REQUEST_TIMEOUT if needed.

Project structure

genwiki.py              Main Flask application
requirements.txt        Python dependencies
README.md               Project documentation
.env.example            Example environment configuration
.gitignore              Git ignore rules
run_windows.ps1         Windows PowerShell runner
run_windows.bat         Windows Command Prompt runner
run_linux.sh            Linux/macOS runner
templates/              Flask HTML templates
static/                 CSS and static assets
logs/                   Runtime logs, ignored by Git

Notes

  • DuckDuckGo snippets are used as grounding context, but important facts should still be verified before publishing.
  • Images are loaded from external search result URLs. Check image licenses before public use.
  • Safe image filtering blocks obvious unsafe results, but no web image filter is perfect.
  • The maintained DuckDuckGo Python package is imported as ddgs; the code also supports the older duckduckgo_search import as a fallback.

Releases

No releases published

Packages

 
 
 

Contributors