Skip to content
semifluxPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Lesson Summarizer (portable)

This project is completely vibecoded slop. Every line was generated by an AI coding agent through prompt-driven iteration, with minimal human review.

Dump any lesson material — slides (PDF), photos, audio, video, text — and get a LaTeX lecture-notes PDF via any OpenAI-compatible LLM (OpenRouter, Ollama, …). Audio/video is transcribed locally (faster-whisper), PDFs are rendered to page images (or sent whole with --as-file), video optionally screenshotted — the model only ever sees text + images.

Cost

With OpenRouter free models (e.g. the default nvidia/nemotron-3-ultra-550b-a55b:free): $0 within free-tier rate limits. Paid models (e.g. qwen/qwen3.8-flash, mistralai/mistral-large-4-0) run ~1–5¢ per lecture; per-job token usage and a cost estimate are shown in the UI and CLI. Free-tier prompts may be used by providers for training — check each model's data policy.

Run (pip)

python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-transcribe.txt   # needed for audio/video
cp .env.example .env   # put LLM_API_KEY=…
uvicorn app.main:app --host 127.0.0.1 --port 8000
# open http://127.0.0.1:8000

API key and model can also be entered in the web UI per-job (key stored only in your browser's localStorage). Set LLM_BASE for a custom endpoint (e.g. local Ollama).

Run (Docker, includes LaTeX + ghostscript + ffmpeg)

cp .env.example .env   # put LLM_API_KEY=…
docker compose up --build
# open http://127.0.0.1:8000

CLI (no UI)

python cli.py slides.pdf lecture.mp3 notes.txt --out ./out --api-key $LLM_API_KEY
python cli.py lecture.mp4 slides.pdf --out ./out --model qwen/qwen3.8-flash

Audio/video is transcribed locally with faster-whisper (large-v3-turbo default, --transcribe-model to change, e.g. large-v3 for max accuracy, --transcribe-lang it). Needs pip install -r requirements-transcribe.txt (first run downloads the model, ~1.6 GB). Transcripts are saved per job.

Video has two independent channels — audio and frames:

python cli.py lecture.mp4                        # transcript only (default)
python cli.py lecture.mp4 --screenshot 0.05      # transcript + frames
python cli.py lecture.mp4 --screenshot 0.05 --no-transcript   # frames only
python cli.py lecture.mp4 --no-transcript        # error: needs --screenshot

--screenshot FPS adds frames-as-photos on top of the transcript (not a replacement). Near-duplicate frames are auto-dropped, capped at 200 per video (SHOT_MAX). --no-transcript drops the audio and keeps only frames — it requires --screenshot, because a raw video can't be sent to a text+images API. Needs ffmpeg.

Reasoning models

Reasoning-capable models on OpenRouter (DeepSeek V4, Kimi, GLM, GPT-5.x, …) can be told how hard to think with --reasoning low|medium|high|off (CLI), the Reasoning dropdown in the UI, or LLM_REASONING in .env. Omit it to use the provider's own default. It's sent as OpenRouter's reasoning request object and ignored by models that don't reason.

Reasoning also gets a hard token ceiling (--reasoning-max-tokens in the CLI, the number field next to the dropdown in the UI, LLM_REASONING_MAX_TOKENS in .env; default 65536). Because OpenRouter accepts either effort or max_tokens (never both), a level is expressed as a token budget clamped to that ceiling:

level budget
(unset) 8192
minimal 2048
low 4096
medium 16384
high 65536

This stops a runaway model from spending the whole output budget on thinking and returning an empty document. off disables reasoning; --reasoning-max-tokens 0 removes the ceiling and goes back to raw effort levels. On models that only support effort, OpenRouter maps the budget to an effort level automatically.

When reasoning is on, the model's step-by-step trace is saved next to the notes as reasoning.md (downloadable in the UI) and its token count is shown as thoughts — reasoning tokens are billed as output, so they're inside the out figure, not on top of it.

PDFs

By default each PDF page is rendered to a JPEG (100 DPI, first 100 pages) and sent as an image, so the model sees the slides — layout, diagrams, equations. This works with any vision model, including local Ollama.

Send PDFs whole instead with --as-file (CLI), the PDFs option in the UI, or PDF_AS_FILE=true in .env. The provider then parses the PDF itself (OpenRouter/OpenAI):

python cli.py slides.pdf --as-file                              # OpenRouter picks the engine
python cli.py slides.pdf --as-file --pdf-engine cloudflare-ai   # free, text-only

Trade-off: the OCR fallback engines return text (at most 8 images), so a slide deck loses its figures — image mode is better for slides, file mode for text-heavy documents (papers, handouts). On OpenRouter the default fallback (mistral-ocr) is billed per page ($2 / 1,000 pages) even with your own key, so use --pdf-engine cloudflare-ai (free) or native on a model that supports files. Whole-file inputs are capped (~50 MB); larger PDFs fall back to page rendering (PDF_MAX_MB).

Transcription only, no notes: python transcribe.py lecture.mp3 --out ./transcripts (local faster-whisper, no API key; --lang it, --model large-v3, --device auto|cpu|cuda, --compute-type auto|int8|int8_float16|float16|float32, --batch-size N). Every notes job also saves its transcripts under data/jobs/<id>/transcripts/, listed as downloadable artifacts in the UI. Same in the web UI without notes: tick “transcription only” next to Summarize — transcripts appear as downloadable .txt artifacts, no LLM call is made.

GPU transcription (NVIDIA and AMD)

faster-whisper uses the GPU automatically when CTranslate2 can see one, and falls back to CPU otherwise. Force it with TRANSCRIBE_DEVICE=cpu|cuda (or --transcribe-device / --device), and pick the math with TRANSCRIBE_COMPUTE_TYPE (default: float16 on GPU, int8 on CPU). The web UI shows the engine it resolved next to the transcribe toggle.

Batched decoding is on by default (TRANSCRIBE_BATCH_SIZE=16, or --transcribe-batch-size / --batch-size; 0 disables it). Whisper's decoder is inherently sequential, which starves a GPU; the batched pipeline chunks the audio with VAD and decodes many segments in parallel. Measured on an RX 7600 with large-v3-turbo: ~11x realtime sequential → ~80x realtime batched (≈9x faster; a 20-minute file went from 134 s to 14 s). Trade-off: batched segments are decoded independently, so there is no cross-segment conditioning.

AMD GPU (ROCm)

CTranslate2 gained official ROCm/HIP support in v4.7.1 and ships GPU wheels, so no source build is needed. The PyPI ctranslate2 wheel is CUDA-only, so swap it for the ROCm one (needs ROCm installed, /dev/kfd accessible, and your user in the video and render groups):

pip install -r requirements-transcribe.txt
PYTHON=.venv/bin/python scripts/install_ct2_rocm.sh   # official ROCm wheel
python -c "import ctranslate2; print(ctranslate2.get_cuda_device_count())"  # -> 1+

CTranslate2 still calls the device cuda on ROCm, so TRANSCRIBE_DEVICE=auto just works. The app also forces CT2_CUDA_ALLOCATOR=cub_caching, because the default allocator hits Memory access fault by GPU node on AMD for audio longer than ~a minute (verified stable up to 20-minute files). Roll back to the CUDA wheel with pip install --force-reinstall ctranslate2.

The default Docker image ships the CUDA wheel and no ROCm runtime, so GPU transcription there needs a ROCm base image plus --device=/dev/kfd --device=/dev/dri --group-add video --group-add render.

LaTeX fix only, no notes: python fix_tex.py notes.tex --rounds 3 (--api-key, --model, --base-url, --reasoning, --reasoning-max-tokens).

Standalone transcriber service (transcriber/)

transcriber/ is the same faster-whisper engine exposed as a small independent HTTP service, plus a drag-and-drop page. Use it when you only need transcripts: run one instance (e.g. on a GPU box), then call it from several machines on the same network. It has its own dependencies and .env; see transcriber/README.md. The summarizer app and transcribe.py above do not need it running — they import the engine directly.

Output per job (data/jobs/<id>/): <Title_Slug>.tex, <Title_Slug>.pdf, <Title_Slug>_dark.pdf (if gs present, title taken from the generated \title{}), transcripts/, reasoning.md (when a reasoning level is set), job.log, usage.json.

Portability notes

  • Needs only Python 3.10+ + pip install -r requirements.txt (+ transcribe reqs for audio/video), or Docker.
  • No GPU needed (faster-whisper runs on CPU); an NVIDIA or AMD/ROCm GPU is used automatically when present. No torch directly.
  • Any OpenAI-compatible endpoint works: OpenRouter, local Ollama (LLM_BASE=http://localhost:11434/v1, any vision-capable model), …
  • Store keys in .env (LLM_API_KEY, LLM_MODEL, LLM_BASE, LLM_REASONING, LLM_REASONING_MAX_TOKENS, PDF_AS_FILE, PDF_ENGINE, TRANSCRIBE_MODEL, TRANSCRIBE_DEVICE, TRANSCRIBE_COMPUTE_TYPE) — never in the repo.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages