Fixed refinement
This commit is contained in:
@@ -11,7 +11,7 @@ from flask import Flask, render_template, request, redirect, url_for, flash, sen
|
||||
from flask_login import LoginManager, login_user, login_required, logout_user, current_user
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from .web_db import db, User, Project, Run, LogEntry
|
||||
from .web_tasks import huey, generate_book_task, regenerate_artifacts_task, rewrite_chapter_task
|
||||
from .web_tasks import huey, generate_book_task, regenerate_artifacts_task, rewrite_chapter_task, refine_bible_task
|
||||
import config
|
||||
from . import utils
|
||||
from . import ai
|
||||
@@ -560,6 +560,28 @@ def clone_project(id):
|
||||
flash(f"Project cloned as '{new_name}'.")
|
||||
return redirect(url_for('view_project', id=new_proj.id))
|
||||
|
||||
@app.route('/project/<int:id>/bible_comparison')
|
||||
@login_required
|
||||
def bible_comparison(id):
|
||||
proj = db.session.get(Project, id) or Project.query.get_or_404(id)
|
||||
if proj.user_id != current_user.id: return "Unauthorized", 403
|
||||
|
||||
bible_path = os.path.join(proj.folder_path, "bible.json")
|
||||
draft_path = os.path.join(proj.folder_path, "bible_draft.json")
|
||||
|
||||
if not os.path.exists(draft_path):
|
||||
flash("No draft found. Please refine the bible first.")
|
||||
return redirect(url_for('review_project', id=id))
|
||||
|
||||
original = utils.load_json(bible_path)
|
||||
new_draft = utils.load_json(draft_path)
|
||||
|
||||
if not original or not new_draft:
|
||||
flash("Error loading bible data. Draft may be corrupt.")
|
||||
return redirect(url_for('review_project', id=id))
|
||||
|
||||
return render_template('bible_comparison.html', project=proj, original=original, new=new_draft)
|
||||
|
||||
@app.route('/project/<int:id>/refine_bible', methods=['POST'])
|
||||
@login_required
|
||||
def refine_bible_route(id):
|
||||
@@ -580,7 +602,7 @@ def refine_bible_route(id):
|
||||
source_type = data.get('source', 'original')
|
||||
selected_keys = data.get('selected_keys')
|
||||
if isinstance(selected_keys, str):
|
||||
try: selected_keys = json.loads(selected_keys)
|
||||
try: selected_keys = json.loads(selected_keys) if selected_keys.strip() else []
|
||||
except: selected_keys = []
|
||||
|
||||
# Start Background Task
|
||||
@@ -598,7 +620,7 @@ def confirm_bible_refinement(id):
|
||||
draft_path = os.path.join(proj.folder_path, "bible_draft.json")
|
||||
bible_path = os.path.join(proj.folder_path, "bible.json")
|
||||
|
||||
if action == 'accept_all':
|
||||
if action == 'accept' or action == 'accept_all':
|
||||
if os.path.exists(draft_path):
|
||||
shutil.move(draft_path, bible_path)
|
||||
flash("Bible updated successfully.")
|
||||
@@ -613,7 +635,7 @@ def confirm_bible_refinement(id):
|
||||
draft = utils.load_json(draft_path)
|
||||
original = utils.load_json(bible_path)
|
||||
|
||||
original = _merge_selected_changes(original, draft, selected_keys)
|
||||
original = story.merge_selected_changes(original, draft, selected_keys)
|
||||
|
||||
with open(bible_path, 'w') as f: json.dump(original, f, indent=2)
|
||||
os.remove(draft_path) # Cleanup draft after merge
|
||||
|
||||
@@ -388,7 +388,7 @@ def refine_bible_task(project_path, instruction, source_type, selected_keys=None
|
||||
|
||||
# If user selected specific changes, merge them into the base
|
||||
# This creates a "Proposed State" to refine further, WITHOUT modifying bible.json
|
||||
if selected_keys and draft_bible:
|
||||
if selected_keys is not None and draft_bible:
|
||||
base_bible = story.merge_selected_changes(base_bible, draft_bible, selected_keys)
|
||||
elif draft_bible:
|
||||
# If no specific keys but source is draft, assume we refine the whole draft
|
||||
|
||||
Reference in New Issue
Block a user