Fixed refinement

This commit is contained in:
=
2026-02-04 22:10:19 -05:00
parent 3a80307cc2
commit df7cee9524
5 changed files with 53 additions and 7 deletions

View File

@@ -397,6 +397,11 @@ def view_project(id):
bible_path = os.path.join(proj.folder_path, "bible.json")
bible_data = utils.load_json(bible_path)
# Check for active refinement or pending draft
draft_path = os.path.join(proj.folder_path, "bible_draft.json")
has_draft = os.path.exists(draft_path)
is_refining = os.path.exists(os.path.join(proj.folder_path, ".refining"))
# Load Personas for dropdown
personas = {}
if os.path.exists(config.PERSONAS_FILE):
@@ -463,7 +468,7 @@ def view_project(id):
'type': f.split('.')[-1].upper()
})
return render_template('project.html', project=proj, bible=bible_data, runs=runs, active_run=latest_run, artifacts=artifacts, cover_image=cover_image, personas=personas, generated_books=generated_books, other_projects=other_projects, locked=locked)
return render_template('project.html', project=proj, bible=bible_data, runs=runs, active_run=latest_run, artifacts=artifacts, cover_image=cover_image, personas=personas, generated_books=generated_books, other_projects=other_projects, locked=locked, has_draft=has_draft, is_refining=is_refining)
@app.route('/project/<int:id>/run', methods=['POST'])
@login_required

View File

@@ -378,6 +378,9 @@ def refine_bible_task(project_path, instruction, source_type, selected_keys=None
try:
bible_path = os.path.join(project_path, "bible.json")
draft_path = os.path.join(project_path, "bible_draft.json")
lock_path = os.path.join(project_path, ".refining")
with open(lock_path, 'w') as f: f.write("running")
base_bible = utils.load_json(bible_path)
if not base_bible: return False
@@ -409,3 +412,5 @@ def refine_bible_task(project_path, instruction, source_type, selected_keys=None
except Exception as e:
utils.log("ERROR", f"Bible refinement task failed: {e}")
return False
finally:
if os.path.exists(lock_path): os.remove(lock_path)

View File

@@ -21,7 +21,7 @@
<div class="card-body bg-light">
<div class="row align-items-center">
<div class="col-md-6">
<form id="refineForm" onsubmit="submitRefine(event)" class="d-flex">
<form id="refineForm" onsubmit="submitRefine(event); return false;" action="javascript:void(0);" class="d-flex">
<input type="hidden" name="source" value="draft">
<input type="hidden" name="selected_keys" id="refineSelectedKeys">
<input type="text" name="instruction" class="form-control me-2" placeholder="Refine this draft further (e.g. 'Fix the name spelling')..." required>

View File

@@ -299,6 +299,12 @@
<div class="card-header bg-light d-flex justify-content-between align-items-center">
<h5 class="mb-0"><i class="fas fa-globe me-2"></i>World Bible & Characters</h5>
<div>
{% if is_refining %}
<span class="badge bg-warning text-dark me-2">
<span class="spinner-border spinner-border-sm me-1"></span> Refining...
</span>
{% endif %}
<a href="/project/{{ project.id }}/review" class="btn btn-sm btn-outline-info me-1">
<i class="fas fa-list-alt me-1"></i> Full Review
</a>
@@ -306,13 +312,37 @@
<button class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#importCharModal" data-bs-toggle="tooltip" title="Import characters from another project to create a shared universe.">
<i class="fas fa-link me-1"></i> Link / Import Series
</button>
{% if has_draft %}
<a href="/project/{{ project.id }}/bible_comparison" class="btn btn-sm btn-warning ms-1 fw-bold">
<i class="fas fa-balance-scale me-1"></i> Review Draft
</a>
{% elif is_refining %}
<button class="btn btn-sm btn-outline-secondary ms-1" disabled>
<i class="fas fa-magic me-1"></i> Refining...
</button>
{% else %}
<button class="btn btn-sm btn-outline-primary ms-1" data-bs-toggle="modal" data-bs-target="#refineBibleModal" data-bs-toggle="tooltip" title="Use AI to bulk-edit characters or plot points based on your instructions.">
<i class="fas fa-magic me-1"></i> Refine
</button>
{% endif %}
{% endif %}
</div>
</div>
<div class="card-body">
{% if has_draft %}
<div class="alert alert-warning shadow-sm mb-3">
<div class="d-flex justify-content-between align-items-center">
<div>
<i class="fas fa-exclamation-circle me-2"></i>
<strong>Draft Pending:</strong> You have an unreviewed Bible refinement waiting.
</div>
<a href="/project/{{ project.id }}/bible_comparison" class="btn btn-warning btn-sm fw-bold">Review Changes</a>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-md-4 border-end">
<h6 class="text-muted text-uppercase small fw-bold mb-3">Project Metadata</h6>

View File

@@ -12,7 +12,7 @@
<p class="text-muted">The AI has generated your characters and plot structure. Review them below and refine if needed.</p>
<!-- Refinement Bar -->
<form id="refineForm" onsubmit="submitRefine(event)" class="mb-4">
<form id="refineForm" onsubmit="submitRefine(event); return false;" action="javascript:void(0);" class="mb-4">
<div class="input-group shadow-sm">
<span class="input-group-text bg-warning text-dark"><i class="fas fa-magic"></i></span>
<input type="text" name="instruction" class="form-control" placeholder="AI Instruction: e.g. 'Change the ending of Book 1', 'Add a plot point about the ring', 'Make the tone darker'" required>
@@ -121,6 +121,12 @@ function submitRefine(event) {
});
}, 2000);
}
})
.catch(err => {
alert("Request failed: " + err);
const btn = form.querySelector('button[type="submit"]');
btn.disabled = false;
btn.innerHTML = 'Refine with AI';
});
}
</script>