feat: reprocess existing transcript via Ollama — modal button + POST /transcripts/{filename}/reprocess

This commit is contained in:
2026-04-01 14:27:15 +02:00
parent 3673e28e73
commit 33ae9dc1d8
3 changed files with 52 additions and 0 deletions
+29
View File
@@ -134,6 +134,35 @@ async def get_transcript(filename: str, user: dict = Depends(current_user)):
return PlainTextResponse(content)
@router.post("/transcripts/{filename}/reprocess")
async def reprocess_transcript(filename: str, body: dict, user: dict = Depends(current_user)):
from output import read_transcript
from fastapi.responses import PlainTextResponse
from llm import OllamaClient
user_dir = os.path.join(user["output_dir"], user["username"])
content = read_transcript(user_dir, filename)
if content is None:
raise HTTPException(status_code=404, detail="Nicht gefunden")
# Strip YAML frontmatter before sending to LLM
body_text = content
if content.startswith("---\n"):
end = content.find("\n---\n", 4)
if end != -1:
body_text = content[end + 5:].lstrip("\n")
cfg = load_config()
instructions = body.get("instructions", "")
client = OllamaClient(base_url=cfg["ollama"]["base_url"])
refined = await client.refine(body_text, instructions=instructions, model=cfg["ollama"]["model"])
# Overwrite same file (keep filename stable, update frontmatter date)
from datetime import datetime
path = os.path.join(user_dir, filename)
with open(path, "w", encoding="utf-8") as f:
now = datetime.now()
f.write(f"---\ndate: {now.isoformat(timespec='seconds')}\ntags: [transkript]\n---\n\n")
f.write(refined if refined.endswith("\n") else refined + "\n")
return PlainTextResponse(refined)
@router.delete("/transcripts/{filename}")
async def delete_transcript(filename: str, user: dict = Depends(current_user)):
user_dir = os.path.join(user["output_dir"], user["username"])