Final changes and update
This commit is contained in:
36
wizard.py
36
wizard.py
@@ -12,21 +12,14 @@ from modules import ai, utils
|
||||
from modules.web_db import db, User, Project
|
||||
|
||||
console = Console()
|
||||
genai.configure(api_key=config.API_KEY)
|
||||
|
||||
# Validate Key on Launch
|
||||
try:
|
||||
list(genai.list_models(page_size=1))
|
||||
ai.init_models()
|
||||
except Exception as e:
|
||||
console.print(f"[bold red]❌ CRITICAL: Gemini API Key check failed.[/bold red]")
|
||||
console.print(f"[bold red]❌ CRITICAL: AI Model Initialization failed.[/bold red]")
|
||||
console.print(f"[red]Error: {e}[/red]")
|
||||
console.print("Please check your .env file and ensure GEMINI_API_KEY is correct.")
|
||||
Prompt.ask("Press Enter to exit...")
|
||||
sys.exit(1)
|
||||
|
||||
logic_name = ai.get_optimal_model("pro") if config.MODEL_LOGIC_HINT == "AUTO" else config.MODEL_LOGIC_HINT
|
||||
model = genai.GenerativeModel(logic_name, safety_settings=utils.SAFETY_SETTINGS)
|
||||
|
||||
# --- DB SETUP FOR WIZARD ---
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{os.path.join(config.DATA_DIR, "bookapp.db")}'
|
||||
@@ -64,7 +57,7 @@ class BookWizard:
|
||||
def ask_gemini_json(self, prompt):
|
||||
text = None
|
||||
try:
|
||||
response = model.generate_content(prompt + "\nReturn ONLY valid JSON.")
|
||||
response = ai.model_logic.generate_content(prompt + "\nReturn ONLY valid JSON.")
|
||||
text = utils.clean_json(response.text)
|
||||
return json.loads(text)
|
||||
except Exception as e:
|
||||
@@ -74,7 +67,7 @@ class BookWizard:
|
||||
|
||||
def ask_gemini_text(self, prompt):
|
||||
try:
|
||||
response = model.generate_content(prompt)
|
||||
response = ai.model_logic.generate_content(prompt)
|
||||
return response.text.strip()
|
||||
except Exception as e:
|
||||
console.print(f"[red]AI Error: {e}[/red]")
|
||||
@@ -413,7 +406,7 @@ class BookWizard:
|
||||
title = Prompt.ask("Book Title (Leave empty for AI)", default=suggestions.get('title', ""))
|
||||
|
||||
# PROJECT NAME
|
||||
default_proj = "".join([c for c in title if c.isalnum() or c=='_']).replace(" ", "_") if title else "New_Project"
|
||||
default_proj = utils.sanitize_filename(title) if title else "New_Project"
|
||||
self.project_name = Prompt.ask("Project Name (Folder)", default=default_proj)
|
||||
|
||||
# Create Project in DB and set path
|
||||
@@ -692,12 +685,11 @@ class BookWizard:
|
||||
console.print(Panel(f"[bold green]✅ Bible saved to: {filename}[/bold green]"))
|
||||
return filename
|
||||
|
||||
def manage_runs(self, job_filename):
|
||||
job_name = os.path.splitext(job_filename)[0]
|
||||
runs_dir = os.path.join(self.project_path, "runs", job_name)
|
||||
def manage_runs(self):
|
||||
runs_dir = os.path.join(self.project_path, "runs")
|
||||
|
||||
if not os.path.exists(runs_dir):
|
||||
console.print("[red]No runs found for this job.[/red]")
|
||||
console.print("[red]No runs found for this project.[/red]")
|
||||
Prompt.ask("Press Enter...")
|
||||
return
|
||||
|
||||
@@ -710,7 +702,7 @@ class BookWizard:
|
||||
|
||||
while True:
|
||||
self.clear()
|
||||
console.print(Panel(f"[bold blue]Runs for: {job_name}[/bold blue]"))
|
||||
console.print(Panel(f"[bold blue]Runs for: {self.project_name}[/bold blue]"))
|
||||
for i, r in enumerate(runs):
|
||||
console.print(f"[{i+1}] {r}")
|
||||
console.print(f"[{len(runs)+1}] Back")
|
||||
@@ -757,10 +749,6 @@ class BookWizard:
|
||||
break
|
||||
elif choice == idx_exit:
|
||||
sys.exit()
|
||||
else:
|
||||
# Legacy or Flat Run
|
||||
self.manage_single_book_folder(run_path)
|
||||
break
|
||||
|
||||
def manage_single_book_folder(self, folder_path):
|
||||
while True:
|
||||
@@ -848,11 +836,11 @@ if __name__ == "__main__":
|
||||
if w.load_bible():
|
||||
bible_path = os.path.join(w.project_path, "bible.json")
|
||||
import main
|
||||
main.run_generation(bible_path)
|
||||
main.run_generation(bible_path, interactive=True)
|
||||
Prompt.ask("\nGeneration complete. Press Enter...")
|
||||
elif choice == 3:
|
||||
# Manage runs for the bible
|
||||
w.manage_runs("bible.json")
|
||||
# Manage runs
|
||||
w.manage_runs()
|
||||
else:
|
||||
break
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user