diff --git a/modules/web_app.py b/modules/web_app.py index 0bee9ad..f1256a7 100644 --- a/modules/web_app.py +++ b/modules/web_app.py @@ -887,6 +887,34 @@ def restart_run(id): flash(f"Started new Run #{new_run.id}" + (" with modifications." if feedback else ".")) return redirect(url_for('view_project', id=run.project_id)) +@app.route('/project//revise_book/', methods=['POST']) +@login_required +def revise_book(run_id, book_folder): + run = db.session.get(Run, run_id) or Run.query.get_or_404(run_id) + if run.project.user_id != current_user.id: return "Unauthorized", 403 + + instruction = request.form.get('instruction') + + # Create new run + new_run = Run(project_id=run.project_id, status="queued") + db.session.add(new_run) + db.session.commit() + + # Task: Apply feedback to Bible, Copy all books EXCEPT this one, then Generate + task = generate_book_task( + new_run.id, + run.project.folder_path, + os.path.join(run.project.folder_path, "bible.json"), + allow_copy=True, + feedback=instruction, + source_run_id=run.id, + keep_cover=True, + exclude_folders=[book_folder] + ) + + flash(f"Started Revision Run #{new_run.id}. Book '{book_folder}' will be regenerated.") + return redirect(url_for('view_project', id=run.project_id)) + @app.route('/run/') @login_required def view_run(id): diff --git a/modules/web_tasks.py b/modules/web_tasks.py index 6fcb849..d70d7be 100644 --- a/modules/web_tasks.py +++ b/modules/web_tasks.py @@ -36,7 +36,7 @@ def db_progress_callback(db_path, run_id, percent): except: break @huey.task() -def generate_book_task(run_id, project_path, bible_path, allow_copy=True, feedback=None, source_run_id=None, keep_cover=False): +def generate_book_task(run_id, project_path, bible_path, allow_copy=True, feedback=None, source_run_id=None, keep_cover=False, exclude_folders=None): """ Background task to run the book generation. """ @@ -147,6 +147,10 @@ def generate_book_task(run_id, project_path, bible_path, allow_copy=True, feedba for item in os.listdir(latest_run_dir): # Copy only folders that look like books and have a manuscript if item.startswith("Book_") and os.path.isdir(os.path.join(latest_run_dir, item)): + if exclude_folders and item in exclude_folders: + utils.log("SYSTEM", f" -> Skipping copy of {item} (Target for revision).") + continue + if os.path.exists(os.path.join(latest_run_dir, item, "manuscript.json")): src = os.path.join(latest_run_dir, item) dst = os.path.join(current_run_dir, item) diff --git a/templates/run_details.html b/templates/run_details.html index a6e3852..aac6b69 100644 --- a/templates/run_details.html +++ b/templates/run_details.html @@ -170,12 +170,38 @@ Check Consistency + + + + {% endfor %}