Added revised book feature.

This commit is contained in:
2026-02-05 08:20:08 -05:00
parent 92336e4f29
commit e6110a6a54
3 changed files with 59 additions and 1 deletions

View File

@@ -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/<int:run_id>/revise_book/<string:book_folder>', 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/<int:id>')
@login_required
def view_run(id):

View File

@@ -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)