Delete app-backup.py
Browse files- app-backup.py +0 -2033
app-backup.py
DELETED
|
@@ -1,2033 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
import json
|
| 4 |
-
import requests
|
| 5 |
-
from datetime import datetime
|
| 6 |
-
import time
|
| 7 |
-
from typing import List, Dict, Any, Generator, Tuple, Optional, Set
|
| 8 |
-
import logging
|
| 9 |
-
import re
|
| 10 |
-
import tempfile
|
| 11 |
-
from pathlib import Path
|
| 12 |
-
import sqlite3
|
| 13 |
-
import hashlib
|
| 14 |
-
import threading
|
| 15 |
-
from contextlib import contextmanager
|
| 16 |
-
from dataclasses import dataclass, field, asdict
|
| 17 |
-
from collections import defaultdict
|
| 18 |
-
import random
|
| 19 |
-
from huggingface_hub import HfApi, upload_file, hf_hub_download
|
| 20 |
-
|
| 21 |
-
# --- Logging setup ---
|
| 22 |
-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 23 |
-
logger = logging.getLogger(__name__)
|
| 24 |
-
|
| 25 |
-
# --- Document export imports ---
|
| 26 |
-
try:
|
| 27 |
-
from docx import Document
|
| 28 |
-
from docx.shared import Inches, Pt, RGBColor, Mm
|
| 29 |
-
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
| 30 |
-
from docx.enum.style import WD_STYLE_TYPE
|
| 31 |
-
from docx.oxml.ns import qn
|
| 32 |
-
from docx.oxml import OxmlElement
|
| 33 |
-
DOCX_AVAILABLE = True
|
| 34 |
-
except ImportError:
|
| 35 |
-
DOCX_AVAILABLE = False
|
| 36 |
-
logger.warning("python-docx not installed. DOCX export will be disabled.")
|
| 37 |
-
|
| 38 |
-
import io
|
| 39 |
-
|
| 40 |
-
# --- Environment variables and constants ---
|
| 41 |
-
FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN", "")
|
| 42 |
-
BRAVE_SEARCH_API_KEY = os.getenv("BRAVE_SEARCH_API_KEY", "")
|
| 43 |
-
API_URL = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
| 44 |
-
MODEL_ID = "dep86pjolcjjnv8"
|
| 45 |
-
DB_PATH = "webnovel_sessions_v2.db"
|
| 46 |
-
|
| 47 |
-
# Target settings for web novel
|
| 48 |
-
TARGET_EPISODES = 40 # 40ํ ์๊ฒฐ
|
| 49 |
-
WORDS_PER_EPISODE = 500 # ๊ฐ ํ๋น 500 ๋จ์ด
|
| 50 |
-
TARGET_WORDS = TARGET_EPISODES * WORDS_PER_EPISODE # ์ด 20000 ๋จ์ด
|
| 51 |
-
|
| 52 |
-
# Web novel genres - from paste-2.txt
|
| 53 |
-
WEBNOVEL_GENRES = {
|
| 54 |
-
"๋ก๋งจ์ค": "Romance",
|
| 55 |
-
"๋กํ": "Romance Fantasy",
|
| 56 |
-
"ํํ์ง": "Fantasy",
|
| 57 |
-
"ํํ": "Modern Fantasy",
|
| 58 |
-
"๋ฌดํ": "Martial Arts",
|
| 59 |
-
"๋ฏธ์คํฐ๋ฆฌ": "Mystery",
|
| 60 |
-
"๋ผ์ดํธ๋
ธ๋ฒจ": "Light Novel"
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
# Complete word list from paste.txt
|
| 64 |
-
complete_word_list = {
|
| 65 |
-
"์บ๋ฆญํฐ": [
|
| 66 |
-
# ์ผ์ ์ง์
(40๊ฐ)
|
| 67 |
-
"์์ฌ", "๊ฐํธ์ฌ", "๊ต์ฌ", "ํ์", "ํ์ฌ์", "ํ๋ก๊ทธ๋๋จธ", "๋์์ด๋", "์๋ฆฌ์ฌ", "๋ฐ๋ฆฌ์คํ", "๋ฏธ์ฉ์ฌ",
|
| 68 |
-
"ํ์๊ธฐ์ฌ", "๋ฐฐ๋ฌ์", "๊ฒฝ์ฐฐ๊ด", "์๋ฐฉ๊ด", "๊ตฐ์ธ", "ํ์ฌ", "๋ณํธ์ฌ", "๊ธฐ์", "์๊ฐ", "ํ๊ฐ",
|
| 69 |
-
"๊ฐ์", "๋ฐฐ์ฐ", "์ด๋์ ์", "๋๋ถ", "์ด๋ถ", "์์ธ", "์ํ์", "๋ถ๋์ฐ์ค๊ฐ์ธ", "์ฒญ์๋ถ", "๊ฒฝ๋น์",
|
| 70 |
-
"์ ํ๋ฒ", "๋ธ๋ก๊ฑฐ", "์ฌ์ง์๊ฐ", "๋ฒ์ญ๊ฐ", "์์์ฌ", "์ฝ์ฌ", "๊ฑด์ถ๊ฐ", "๊ณผํ์", "์์ง๋์ด", "์กฐ์ข
์ฌ",
|
| 71 |
-
|
| 72 |
-
# ํํ์ง/๋ชจํ (25๊ฐ)
|
| 73 |
-
"๊ธฐ์ฌ", "๋ง๋ฒ์ฌ", "๋๋", "ํด์ ", "๋ชจํ๊ฐ", "์ฉ์ฌ", "ํ์", "์ฐ๊ธ์ ์ฌ", "๋ง๋
", "๋๋ฃจ์ด๋",
|
| 74 |
-
"์์ ์์ธ", "๋์ฅ์ฅ์ด", "์์ธ๊ธธ๋์ฅ", "์", "์ฌ์", "์์", "๊ณต์ฃผ", "๊ท์กฑ", "๊ธฐ์ฌ๋จ์ฅ", "๋ง๋ฒํ๊ต๊ต์ฅ",
|
| 75 |
-
"๋ณด๋ฌผ์ฌ๋ฅ๊พผ", "์ง๋์ ์์", "๋ชฌ์คํฐ์ฌ๋ฅ๊พผ", "๋์ ํํ๊ฐ", "๊ธธ๋๋ง์คํฐ",
|
| 76 |
-
|
| 77 |
-
# ๋ฏธ์คํฐ๋ฆฌ/๋ฒ์ฃ (15๊ฐ)
|
| 78 |
-
"ํ์ ", "ํ์ฌ", "ํ๋กํ์ผ๋ฌ", "๋ฒ์ํ์", "์คํ์ด", "ํด์ปค", "์ฌ๊ธฐ๊พผ", "๋ชฉ๊ฒฉ์", "์ฉ์์", "์ ๋ณด์",
|
| 79 |
-
"๋ฐ์์
์", "์์กฐ์ ๋ฌธ๊ฐ", "๊ธ๊ณ ํธ์ด๋ฒ", "์ถ๋ฆฌ์๊ฐ", "์ฌ๋ฆฝํ์ ",
|
| 80 |
-
|
| 81 |
-
# ํธ๋ฌ/์ด์์ฐ (10๊ฐ)
|
| 82 |
-
"ํด๋ง์ฌ", "์๋งค", "๋ฌด๋น", "์ฌ๋ น์ฐ๊ตฌ๊ฐ", "๋ฑํ์ด์ด", "๋๋์ธ๊ฐ", "์ ๋ น", "์
๋ง์ฌ๋ฅ๊พผ", "์ ์ฃผ๋ฐ์์", "์์ธ์",
|
| 83 |
-
|
| 84 |
-
# SF/๋ฏธ๋ (10๊ฐ)
|
| 85 |
-
"์ฐ์ฃผ๋นํ์ฌ", "๋ก๋ด๊ณตํ์", "AI๊ฐ๋ฐ์", "์ฌ์ด๋ณด๊ทธ", "ํ์ํธ๋๋ธ๋ฌ", "์ฐ์ฃผํด์ ", "ํ
๋ผํฌ๋จธ", "์ ์ ๊ณตํ์", "ํ๋ก๊ทธ๋จ๊ธฐ์ ์", "์์๋ฌผ๋ฆฌํ์"
|
| 86 |
-
],
|
| 87 |
-
|
| 88 |
-
"๋ฌผ๊ฑด": [
|
| 89 |
-
# ์ผ์์ฉํ (40๊ฐ)
|
| 90 |
-
"์ด์ ", "์ง๊ฐ", "ํด๋ํฐ", "์๊ฒฝ", "์๊ณ", "๊ฐ๋ฐฉ", "์ฐ์ฐ", "์ ๋ฐ", "๋ชจ์", "์ค์นดํ",
|
| 91 |
-
"์ฑ
", "๋
ธํธ", "ํ", "์นด๋ฉ๋ผ", "์ด์ดํฐ", "๋
ธํธ๋ถ", "์์ ๊ฑฐ", "์๋์ฐจ์ด์ ", "์ ๋ถ์ฆ", "์ ์ฉ์นด๋",
|
| 92 |
-
"๊ฑฐ์ธ", "๋น", "์์๊ฑด", "๋ผ์ดํฐ", "์์ ๋ฑ", "๊ฐ์", "ํ
์ดํ", "์ถฉ์ ๊ธฐ", "๋ง์คํฌ", "์ฅ๊ฐ",
|
| 93 |
-
"๋ฌผ๋ณ", "๋์๋ฝ", "์ฝํต", "ํ์ฅํ", "ํฅ์", "์ ๊ธ๋ผ์ค", "๋ฐฐ๋ญ", "์ฌ๊ถ", "ํฐ์ผ", "๋์ ",
|
| 94 |
-
|
| 95 |
-
# ํน๋ณํ ๋ฌผ๊ฑด (25๊ฐ)
|
| 96 |
-
"๋ณด๋ฌผ์ง๋", "๊ณ ๋์ ๋ฌผ", "๋ง๋ฒ๋ฐ์ง", "์์ ๊ตฌ์ฌ", "๋น๋ฐ์ผ๊ธฐ", "์ํธ๋ฌธ์", "๊ธํ", "๋ณด์", "์๊ด", "๊ฒ",
|
| 97 |
-
"๋ง๋ฒ์งํก์ด", "๋ฌผ์ฝ", "์ฃผ๋ฌธ์", "๋ด์ธ๋์์", "์ ๋นํ์ด์ ", "๊ณ ๋์์ ", "๋์นจ๋ฐ", "๋ง์๊ฒฝ", "๋ชจ๋์๊ณ", "์ค๋ฅด๊ณจ",
|
| 98 |
-
"๋ถ์ ", "๋ฉ๋ฌ", "์ธ์ฅ", "๋๋ฃจ๋ง๋ฆฌ", "์ ์ฑํ์ ๋ฌผ",
|
| 99 |
-
|
| 100 |
-
# ํ๋ ๊ธฐ์ (15๊ฐ)
|
| 101 |
-
"๋๋ก ", "VRํค๋์
", "์ค๋งํธ์์น", "ํ๋ธ๋ฆฟ", "๋ฌด์ ์ด์ดํฐ", "์ก์
์บ ", "์ ์์ฑ
๋ฆฌ๋", "๊ฒ์๊ธฐ", "์ค๋งํธํ๊ธฐ๊ธฐ", "3Dํ๋ฆฐํฐ",
|
| 102 |
-
"ํ๋ก๊ทธ๋จ์ฅ์น", "AI์คํผ์ปค", "์ ๊ธฐ์๋์ฐจํค", "์์ฒด์ธ์์ฅ์น", "๋๋
ธ์นฉ",
|
| 103 |
-
|
| 104 |
-
# ์ฆ๊ฑฐ/๋จ์ (10๊ฐ)
|
| 105 |
-
"ํธ์ง", "์ฌ์ง", "๋
น์๊ธฐ", "ํํ", "์ง๋ฌธ", "ํํผ", "์ฐข์ด์ง์ท", "๋ช
ํจ", "์์์ฆ", "๋ฉ๋ชจ",
|
| 106 |
-
|
| 107 |
-
# ๋ฌด๊ธฐ/๋๊ตฌ (10๊ฐ)
|
| 108 |
-
"๋จ๊ฒ", "ํ", "๋ฐฉํจ", "ํญํ", "ํจ์ ", "๋ฐง์ค", "์๋ฌผ์ ", "์ฒ ์ฌ", "๋ง์น", "ํ๋ถ"
|
| 109 |
-
],
|
| 110 |
-
|
| 111 |
-
"์ฅ์": [
|
| 112 |
-
# ์ผ์ ์ฅ์ (35๊ฐ)
|
| 113 |
-
"์ง", "ํ๊ต", "ํ์ฌ", "๋ณ์", "์ํ", "๋งํธ", "์นดํ", "๋ ์คํ ๋", "๊ณต์", "๋์๊ด",
|
| 114 |
-
"์ํ๊ด", "ํฌ์ค์ฅ", "๋ฏธ์ ๊ด", "๋ฐฑํ์ ", "์งํ์ฒ ์ญ", "๋ฒ์ค์ ๋ฅ์ฅ", "๊ณตํญ", "ํธํ
", "ํธ์์ ", "์ฃผ์ฐจ์ฅ",
|
| 115 |
-
"๋์ดํฐ", "์ํํธ", "์ฌ๋ฌด์ค", "๊ต์ค", "์ฅ์", "์งํ์ค", "์๋ฆฌ๋ฒ ์ดํฐ", "๋ณต๋", "ํ์ฅ์ค", "์ฃผ๋ฐฉ",
|
| 116 |
-
"๋ฐ์ฝ๋", "์ ์", "์ฐจ๊ณ ", "์ฐฝ๊ณ ", "๋ค๋ฆฌ",
|
| 117 |
-
|
| 118 |
-
# ์์ฐ ์ฅ์ (15๊ฐ)
|
| 119 |
-
"์ฒ", "๋ฐ๋ค", "์ฐ", "๊ฐ", "ํธ์", "๋๊ตด", "์ ๋ฒฝ", "ํญํฌ", "๊ณ๊ณก", "์ฌ๋ง",
|
| 120 |
-
"์ฌ", "ํด๋ณ", "๋คํ", "๋ช์ง", "๋นํ",
|
| 121 |
-
|
| 122 |
-
# ํน๋ณํ ์ฅ์ (15๊ฐ)
|
| 123 |
-
"์ฑ", "๋์ ", "๋ง๋ฒํ๊ต", "์ ์ ", "์งํ๋ฌ์ง", "๊ณ ๋์ ์ ", "๋ฏธ๋ก", "ํ", "๊ฐ์ฅ", "์๊ถ",
|
| 124 |
-
"๋น๋ฐ๊ธฐ์ง", "์คํ์ค", "์ฒ๋ฌธ๋", "๋ฑ๋", "ํํ",
|
| 125 |
-
|
| 126 |
-
# ๋์ ์ฅ์ (10๊ฐ)
|
| 127 |
-
"๊ด์ฅ", "์์ฅ", "ํญ๊ตฌ", "๊ธฐ์ฐจ์ญ", "๋ค๋ฆฌ", "๊ณจ๋ชฉ๊ธธ", "๋๋ก", "๊ต์ฐจ๋ก", "๋ถ์๋", "๊ณต์ฌ์ฅ",
|
| 128 |
-
|
| 129 |
-
# ๋ฏธ์คํฐ๋ฆฌ ์ฅ์ (5๊ฐ)
|
| 130 |
-
"๋ฒ์ฃํ์ฅ", "์ทจ์กฐ์ค", "๋ฒ์", "์ฆ๊ฑฐ๋ณด๊ด์ค", "๋ฐ์ค"
|
| 131 |
-
],
|
| 132 |
-
|
| 133 |
-
"์ฌ๊ฑด": [
|
| 134 |
-
# ์ผ์ ์ฌ๊ฑด (30๊ฐ)
|
| 135 |
-
"๋ง๋จ", "์ด๋ณ", "์ฝ์", "์ง๊ฐ", "์ค์", "์คํด", "ํํด", "์ ๋ฌผ", "ํํฐ", "์ด์ฌ",
|
| 136 |
-
"์ทจ์
", "ํด์ฌ", "์ํ", "์กธ์
", "๊ฒฐํผ", "์์ผ", "์ฌ๊ณ ", "์
์", "์ฌํ", "๊ท๊ตญ",
|
| 137 |
-
"๋ถ์ค", "๋ฐ๊ฒฌ", "๊ณ ๋ฐฑ", "๊ฑฐ์ ", "์ฑ๊ณต", "์คํจ", "๋์ ", "ํฌ๊ธฐ", "์์", "๋",
|
| 138 |
-
|
| 139 |
-
# ๋ชจํ/์ก์
(20๊ฐ)
|
| 140 |
-
"์ถ๊ฒฉ", "ํ์ถ", "์ ์
", "๊ตฌ์ถ", "์ ํฌ", "๊ฒฐํฌ", "๋งค๋ณต", "์ต๊ฒฉ", "๋ฐฉ์ด", "ํํด",
|
| 141 |
-
"ํํ", "๋ฐ๊ฒฌ", "ํจ์ ", "๋ฐฐ์ ", "๋๋งน", "๊ฑฐ๋", "ํ์", "์๊ธฐ", "์ญ์ ", "์น๋ฆฌ",
|
| 142 |
-
|
| 143 |
-
# ๋ฏธ์คํฐ๋ฆฌ (15๊ฐ)
|
| 144 |
-
"์ค์ข
", "์ด์ธ", "๋๋", "์์กฐ", "ํ๋ฐ", "๋ฉ์น", "๋ชฉ๊ฒฉ", "์ถ๋ฆฌ", "์ฌ๋ฌธ", "์ฌํ",
|
| 145 |
-
"์ฆ๊ฑฐ๋ฐ๊ฒฌ", "์๋ฆฌ๋ฐ์ด๋ถ๊ดด", "์ ์ฒดํญ๋ก", "์๋ฐฑ", "๋ฌด์ฃ์๋ฐฉ",
|
| 146 |
-
|
| 147 |
-
# ์ด์์ฐ/ํํ์ง (10๊ฐ)
|
| 148 |
-
"์ ์ฃผ", "์ถ๋ณต", "์ํ", "๋ด์ธ", "๊ฐ์ฑ", "๋ณ์ ", "์์ธ", "๊ธฐ์ ", "๋ถํ", "์๋ฉธ",
|
| 149 |
-
|
| 150 |
-
# ๋ก๋งจ์ค/๊ฐ์ (5๊ฐ)
|
| 151 |
-
"์ฒซ๋ง๋จ", "๋ฐ์ดํธ", "ํ๋กํฌ์ฆ", "์ด๋ณ", "์ฌํ"
|
| 152 |
-
],
|
| 153 |
-
|
| 154 |
-
"๊ฐ์ /์ํ": [
|
| 155 |
-
# ๊ธฐ๋ณธ ๊ฐ์ (25๊ฐ)
|
| 156 |
-
"๊ธฐ์จ", "์ฌํ", "๋ถ๋
ธ", "๋๋ ค์", "๋๋", "ํ์ค", "์ ๋ขฐ", "๊ธฐ๋", "์์น์ฌ", "์ฃ์ฑ
๊ฐ",
|
| 157 |
-
"์๋ถ์ฌ", "์งํฌ", "๋ถ๋ฌ์", "ํฌ๋ง", "์ ๋ง", "์ฌ๋", "์ฆ์ค", "๋์ ", "๊ฐ์ฌ", "ํํ",
|
| 158 |
-
"์๋", "์ด์กฐ", "๋นํฉ", "ํฅ๋ถ", "์ค๋ง",
|
| 159 |
-
|
| 160 |
-
# ์ํ (20๊ฐ)
|
| 161 |
-
"ํผ๊ณค", "ํ๊ธฐ์ฐธ", "์กธ๋ฆผ", "๋ฐฐ๊ณ ํ", "๋ชฉ๋ง๋ฆ", "์ํ", "๊ฑด๊ฐํจ", "์ทจํจ", "๋ฉ๋ฏธ", "ํ๊ธฐ์ฆ",
|
| 162 |
-
"์ง์ค", "์ฐ๋ง", "๊ธด์ฅ", "ํธ์", "๋ถ์", "ํ์จ", "ํผ๋", "ํ์ ", "์์ฌ", "๋ง์ค์",
|
| 163 |
-
|
| 164 |
-
# ๋ณต์กํ ๊ฐ์ (10๊ฐ)
|
| 165 |
-
"๊ทธ๋ฆฌ์", "ํ์ ํจ", "๋ฟ๋ฏํจ", "์ฐ์ฐํจ", "์์ดํจ", "๋ฏธ์ํจ", "๊ณ ๋ง์", "์ด์ํจ", "์ฅ์ค๋ฌ์", "๋ต๋ตํจ",
|
| 166 |
-
|
| 167 |
-
# ๊ทน๋จ์ ๊ฐ์ (5๊ฐ)
|
| 168 |
-
"ํํฌ", "์ ๊ท", "๊ณตํฌ", "์ด์ ", "๋ฌด๊ธฐ๋ ฅ"
|
| 169 |
-
],
|
| 170 |
-
|
| 171 |
-
"์๊ฐ/๋": [
|
| 172 |
-
# ํ๋ฃจ ์๊ฐ (10๊ฐ)
|
| 173 |
-
"์๋ฒฝ", "์์นจ", "์ค์ ", "์ ์ค", "์คํ", "์ ๋
", "๋ฐค", "์์ ", "๋ํ๋
", "ํด์ง๋
",
|
| 174 |
-
|
| 175 |
-
# ๊ณ์ /๋ ์จ์๊ธฐ (8๊ฐ)
|
| 176 |
-
"๋ด", "์ฌ๋ฆ", "๊ฐ์", "๊ฒจ์ธ", "์ฅ๋ง์ฒ ", "ํ์ ๊ธฐ", "์ฐ๋ง", "์ฐ์ด",
|
| 177 |
-
|
| 178 |
-
# ํน๋ณํ ๋ (12๊ฐ)
|
| 179 |
-
"์์ผ", "๊ธฐ๋
์ผ", "๋ช
์ ", "์ฃผ๋ง", "ํด์ผ", "์ํ๋ ", "๋ฉด์ ๋ ", "์ด์ฌ๋ ", "๊ฒฐํผ์๋ ", "์กธ์
์๋ ",
|
| 180 |
-
"์ฒซ์ถ๊ทผ", "๋ง์ง๋ง๋ ",
|
| 181 |
-
|
| 182 |
-
# ์๊ฐ ํํ (10๊ฐ)
|
| 183 |
-
"์ง๊ธ", "๋ฐฉ๊ธ", "์กฐ๊ธ์ ", "๋์ค์", "์ธ์ ๊ฐ", "์๋ ", "๋ฏธ๋", "๊ณผ๊ฑฐ", "ํ์ฌ", "์์"
|
| 184 |
-
],
|
| 185 |
-
|
| 186 |
-
"๋ ์จ/์์ฐํ์": [
|
| 187 |
-
# ์ผ๋ฐ ๋ ์จ (20๊ฐ)
|
| 188 |
-
"๋ง์", "ํ๋ฆผ", "๋น", "๋", "๋ฐ๋", "์๊ฐ", "์๋ฆฌ", "์ด์ฌ", "๋ฌด์ง๊ฐ", "๋ฒ๊ฐ",
|
| 189 |
-
"์ฒ๋ฅ", "์ฐ๋ฐ", "ํํ", "ํญ์ค", "ํญ์ผ", "ํํ", "๋ฏธ์ธ๋จผ์ง", "ํฉ์ฌ", "๊ตฌ๋ฆ", "ํ๋น",
|
| 190 |
-
|
| 191 |
-
# ์์ฐํ์ (10๊ฐ)
|
| 192 |
-
"์ผ์ถ", "์ผ๋ชฐ", "์์", "์ผ์", "์ ์ฑ", "์ค๋ก๋ผ", "์กฐ์", "ํ๋", "์ง์ง", "ํ์ฐ"
|
| 193 |
-
],
|
| 194 |
-
|
| 195 |
-
"์๊น/๋น": [
|
| 196 |
-
# ๊ธฐ๋ณธ์ (15๊ฐ)
|
| 197 |
-
"๋นจ๊ฐ", "ํ๋", "๋
ธ๋", "์ด๋ก", "์ฃผํฉ", "๋ณด๋ผ", "๋ถํ", "ํ์", "๊ฒ์ ", "ํ์",
|
| 198 |
-
"๊ฐ์", "ํ๋์", "์ฐ๋์", "๋จ์", "๋ฒ ์ด์ง",
|
| 199 |
-
|
| 200 |
-
# ๋น/์ง๊ฐ (10๊ฐ)
|
| 201 |
-
"๋ฐ์ง์", "์ด๋ ", "๊ทธ๋ฆผ์", "๋น", "ํฌ๋ช
", "๋ถํฌ๋ช
", "๋ฌด๊ด", "์ ๊ด", "ํ๊ด", "์ผ๊ด"
|
| 202 |
-
],
|
| 203 |
-
|
| 204 |
-
"์๏ฟฝ๏ฟฝ/์ํฅ": [
|
| 205 |
-
# ์ผ์์๋ฆฌ (20๊ฐ)
|
| 206 |
-
"๋ฐ์๋ฆฌ", "๋ฌธ์๋ฆฌ", "์ข
์๋ฆฌ", "์๋์๋ฆฌ", "์ ํ๋ฒจ", "๋
ธํฌ์๋ฆฌ", "๋ฐ์์๋ฆฌ", "ํํ๋", "์ฝง๋
ธ๋", "ํ์จ",
|
| 207 |
-
"์์์๋ฆฌ", "์ธ์์๋ฆฌ", "๊ณ ํจ์๋ฆฌ", "์์ญ์", "์ฌ์ฅ์๋ฆฌ", "์จ์๋ฆฌ", "๊ธฐ์นจ์๋ฆฌ", "์ฌ์ฑ๊ธฐ", "ํํ์๋ฆฌ", "์ฝ๊ณจ์ด",
|
| 208 |
-
|
| 209 |
-
# ์์ฐ์๋ฆฌ (10๊ฐ)
|
| 210 |
-
"๋ฐ๋์๋ฆฌ", "๋น์๋ฆฌ", "ํ๋์๋ฆฌ", "์์๋ฆฌ", "๋ฒ๋ ์๋ฆฌ", "์ฒ๋ฅ์๋ฆฌ", "๋๋ญ์์๋ฆฌ", "๋ฌผ์๋ฆฌ", "๋ถํ๋์๋ฆฌ", "์ง์ง์๋ฆฌ"
|
| 211 |
-
],
|
| 212 |
-
|
| 213 |
-
"์์/์๋ฆฌ": [
|
| 214 |
-
# ํ์ (20๊ฐ)
|
| 215 |
-
"๊น์น", "๋์ฅ์ฐ๊ฐ", "๋ถ๊ณ ๊ธฐ", "๋น๋น๋ฐฅ", "๋ก๋ณถ์ด", "๊น๋ฐฅ", "๋ผ๋ฉด", "์ผ๊ฒน์ด", "๋๋ฉด", "๊ฐ๋นํ",
|
| 216 |
-
"์ก์ฑ", "์ ", "์๋๋ถ์ฐ๊ฐ", "์ผ๊ณํ", "๊ตญ๋ฐฅ", "์๋ฐฅ", "๋ณถ์๋ฐฅ", "๋ง๋", "๋ถ์นจ๊ฐ", "์ฃฝ",
|
| 217 |
-
|
| 218 |
-
# ์ธ๊ตญ์์ (15๊ฐ)
|
| 219 |
-
"ํ์คํ", "ํผ์", "์คํ
์ดํฌ", "์ค์", "๋ผ๋ฉ", "์๋ฌ๋", "์๋์์น", "ํ๋ฒ๊ฑฐ", "ํ์ฝ", "์ปค๋ฆฌ",
|
| 220 |
-
"์๊ตญ์", "๋ค์ฌ", "์ผ๋ฐฅ", "๋ฆฌ์กฐ๋", "๋ธ๋ฐ์น",
|
| 221 |
-
|
| 222 |
-
# ๊ฐ์/์๋ฃ (15๊ฐ)
|
| 223 |
-
"์ปคํผ", "์ฐจ", "์ฃผ์ค", "๋งฅ์ฃผ", "์์ธ", "๋นต", "์ผ์ดํฌ", "์ฟ ํค", "์ด์ฝ๋ฆฟ", "์์ด์คํฌ๋ฆผ",
|
| 224 |
-
"๊ณผ์ผ", "ํ์ฝ", "๊ฐ์์นฉ", "์ ค๋ฆฌ", "์ฌํ"
|
| 225 |
-
],
|
| 226 |
-
|
| 227 |
-
"๋์/ํ๋": [
|
| 228 |
-
# ์ผ์ ๋์ (25๊ฐ)
|
| 229 |
-
"๊ฑท๊ธฐ", "๋ฐ๊ธฐ", "์๊ธฐ", "์๊ธฐ", "๋๊ธฐ", "์ผ์ด๋๊ธฐ", "๋์๋ณด๊ธฐ", "์ํ๋ค๊ธฐ", "๊ณ ๊ฐ๋๋์ด๊ธฐ", "๋ฏธ์์ง๊ธฐ",
|
| 230 |
-
"์ฐก๊ทธ๋ฆฌ๊ธฐ", "๋๊ฐ๊ธฐ", "ํํํ๊ธฐ", "๊ธฐ์ง๊ฐ์ผ๊ธฐ", "์จ์ฌ๊ธฐ", "๋จน๊ธฐ", "๋ง์๊ธฐ", "๋งํ๊ธฐ", "๋ฃ๊ธฐ", "๋ณด๊ธฐ",
|
| 231 |
-
"๋ง์ง๊ธฐ", "์ก๊ธฐ", "๋๊ธฐ", "์ด๊ธฐ", "๋ซ๊ธฐ",
|
| 232 |
-
|
| 233 |
-
# ํน๋ณํ ๋์ (15๊ฐ)
|
| 234 |
-
"์จ๊ธฐ", "์ฐพ๊ธฐ", "๋๋ง์น๊ธฐ", "์ซ๊ธฐ", "์ธ์ฐ๊ธฐ", "๋ฐฉ์ดํ๊ธฐ", "๊ณต๊ฒฉํ๊ธฐ", "์ ํํ๊ธฐ", "๊ธฐ์ด๊ฐ๊ธฐ", "์์ํ๊ธฐ",
|
| 235 |
-
"์ถค์ถ๊ธฐ", "๋
ธ๋ํ๊ธฐ", "๊ทธ๋ฆฌ๊ธฐ", "์ฐ๊ธฐ", "์ฐ์ฃผํ๊ธฐ"
|
| 236 |
-
],
|
| 237 |
-
|
| 238 |
-
"๊ด๊ณ": [
|
| 239 |
-
# ๊ฐ์กฑ (10๊ฐ)
|
| 240 |
-
"๋ถ๋ชจ", "์๋
", "ํ์ ", "์๋งค", "์กฐ๋ถ๋ชจ", "์์", "๋ฐฐ์ฐ์", "์ฌ์ด", "์ผ์ด", "์ด๋ชจ",
|
| 241 |
-
|
| 242 |
-
# ์ฌํ๊ด๊ณ (15๊ฐ)
|
| 243 |
-
"์น๊ตฌ", "์ฐ์ธ", "๋๋ฃ", "์์ฌ", "๋ถํ", "์ด์", "์ค์น", "์ ์", "ํํธ๋", "๋ผ์ด๋ฒ",
|
| 244 |
-
"์ ", "๋์ง", "์ง์ธ", "๋ฏ์ ์ฌ๋", "์๋"
|
| 245 |
-
],
|
| 246 |
-
|
| 247 |
-
"๋ฅ๋ ฅ/ํน์ฑ": [
|
| 248 |
-
# ์ผ๋ฐ ๋ฅ๋ ฅ (15๊ฐ)
|
| 249 |
-
"์ง๋ฅ", "์ฒด๋ ฅ", "์๋", "ํ", "๋ฏผ์ฒฉ์ฑ", "์ฐฝ์๋ ฅ", "๊ธฐ์ต๋ ฅ", "์ง์ค๋ ฅ", "๋ฆฌ๋์ญ", "๊ณต๊ฐ๋ฅ๋ ฅ",
|
| 250 |
-
"์ ๋จธ๊ฐ๊ฐ", "์ธ๋ด์ฌ", "์ฉ๊ธฐ", "์ง๊ด", "์ค๋๋ ฅ",
|
| 251 |
-
|
| 252 |
-
# ํน์ ๋ฅ๋ ฅ (10๊ฐ)
|
| 253 |
-
"ํฌ์", "ํ
๋ ํ์", "์์ง๋ ฅ", "์น์ ๋ฅ๋ ฅ", "๋ณ์ ", "ํฌ๋ช
ํ", "๋นํ", "์๊ฐ์กฐ์", "์ ์ ์กฐ์", "์์์กฐ์"
|
| 254 |
-
],
|
| 255 |
-
|
| 256 |
-
"์ํฉ/์กฐ๊ฑด": [
|
| 257 |
-
# ์ผ๋ฐ ์ํฉ (20๊ฐ)
|
| 258 |
-
"๋น์์ฌํ", "์ผ์", "ํด๊ฐ", "๊ทผ๋ฌด์ค", "์์
์ค", "์ด์ ์ค", "๋๊ธฐ์ค", "ํ์์ค", "์์ฌ์ค", "์ด๋์ค",
|
| 259 |
-
"์ ์๋์ค", "๊ณต๋ถ์ค", "์ค๋น์ค", "์ฌํ์ค", "์น๋ฃ์ค", "ํ๋ จ์ค", "๊ฒฝ์์ค", "ํ์์ค", "์กฐ์ฌ์ค", "๋ํผ์ค"
|
| 260 |
-
],
|
| 261 |
-
|
| 262 |
-
"๋ชฉ์ /๋๊ธฐ": [
|
| 263 |
-
# ๊ธฐ๋ณธ ๋๊ธฐ (20๊ฐ)
|
| 264 |
-
"์์กด", "๋ณต์", "์ฌ๋", "๋", "๋ช
์", "๊ถ๋ ฅ", "์ง์", "์์ ", "์ ์", "ํํ",
|
| 265 |
-
"ํ๋ณต", "์ฑ๊ณต", "์ธ์ ", "๋ณดํธ", "๋ฐ๊ฒฌ", "์ฑ์ฅ", "์น์ ", "ํํด", "์ง์ค", "ํฌ๋ง"
|
| 266 |
-
]
|
| 267 |
-
}
|
| 268 |
-
|
| 269 |
-
# Genre elements from paste-2.txt
|
| 270 |
-
GENRE_ELEMENTS = {
|
| 271 |
-
"๋ก๋งจ์ค": {
|
| 272 |
-
"key_elements": ["๊ฐ์ ์ ", "์คํด์ ํํด", "๋ฌ์ฝคํ ์๊ฐ", "์งํฌ", "๊ณ ๋ฐฑ"],
|
| 273 |
-
"popular_tropes": ["๊ณ์ฝ์ฐ์ ", "์ฌ๋ฒ๊ณผ ํ๋ฏผ", "์ฒซ์ฌ๋ ์ฌํ", "์ง์ฌ๋", "์ผ๊ฐ๊ด๊ณ"],
|
| 274 |
-
"must_have": ["์ฌ์ฟต ํฌ์ธํธ", "๋ฌ๋ฌํ ๋์ฌ", "๊ฐ์ ๋ฌ์ฌ", "์คํจ์ญ", "ํดํผ์๋ฉ"],
|
| 275 |
-
"episode_structure": "๊ฐ์ ์ ๋กค๋ฌ์ฝ์คํฐ, ๋งค ํ ๋ ์ค๋ ํฌ์ธํธ"
|
| 276 |
-
},
|
| 277 |
-
"๋กํ": {
|
| 278 |
-
"key_elements": ["ํ๊ท/๋น์", "์์ ์ง์", "์ด๋ช
๋ณ๊ฒฝ", "๋ง๋ฒ/๊ฒ์ ", "์ ๋ถ ์์น"],
|
| 279 |
-
"popular_tropes": ["์
๋
๊ฐ ๋์๋ค", "ํ๋
๊ฐ์ฑ", "๊ณ์ฝ๊ฒฐํผ", "์ง์ฐฉ๋จ์ฃผ", "์ญํ๋ "],
|
| 280 |
-
"must_have": ["์ฐจ์์ด๋ ์ค์ ", "๋จผ์นํจ ์์", "๋ก๋งจ์ค", "๋ณต์", "์ฑ์ฅ"],
|
| 281 |
-
"episode_structure": "์์ ์ ๊ฐ ๋นํ๊ธฐ, ๋งค ํ ์๋ก์ด ๋ณ์"
|
| 282 |
-
},
|
| 283 |
-
"ํํ์ง": {
|
| 284 |
-
"key_elements": ["๋ง๋ฒ์ฒด๊ณ", "๋ ๋ฒจ์
", "๋์ ", "๊ธธ๋", "๋ชจํ"],
|
| 285 |
-
"popular_tropes": ["ํ๊ท", "์์คํ
", "๋จผ์นํจ", "ํ๋ ํผ์ค", "๊ฐ์ฑ"],
|
| 286 |
-
"must_have": ["์ฑ์ฅ ๊ณก์ ", "์ ํฌ์ฌ", "์ธ๊ณ๊ด", "๋๋ฃ", "์ต์ข
๋ณด์ค"],
|
| 287 |
-
"episode_structure": "์ ์ง์ ๊ฐํด์ง, ์๋ก์ด ๋์ ๊ณผ ๊ทน๋ณต"
|
| 288 |
-
},
|
| 289 |
-
"ํํ": {
|
| 290 |
-
"key_elements": ["์จ๊ฒจ์ง ๋ฅ๋ ฅ", "์ผ์๊ณผ ๋น์ผ์", "๋์ ํํ์ง", "๋ฅ๋ ฅ์ ์ฌํ", "๊ฐ์ฑ"],
|
| 291 |
-
"popular_tropes": ["ํํฐ", "๊ฒ์ดํธ", "๊ธธ๋", "๋ญํน", "์์ดํ
"],
|
| 292 |
-
"must_have": ["ํ์ค๊ฐ", "๋ฅ๋ ฅ ๊ฐ์ฑ", "์ฌํ ์์คํ
", "์ก์
", "์ฑ์ฅ"],
|
| 293 |
-
"episode_structure": "์ผ์ ์ ๋น์ผ์ ๋ฐ๊ฒฌ, ์ ์ง์ ์ธ๊ณ๊ด ํ์ฅ"
|
| 294 |
-
},
|
| 295 |
-
"๋ฌดํ": {
|
| 296 |
-
"key_elements": ["๋ฌด๊ณต", "๋ฌธํ", "๊ฐํธ", "๋ณต์", "์ํ"],
|
| 297 |
-
"popular_tropes": ["์ฒ์ฌ", "ํ๊ธ์์ ์ต๊ฐ", "๊ธฐ์ฐ", "ํ์", "๋ง๊ต"],
|
| 298 |
-
"must_have": ["๋ฌด๊ณต ์๋ จ", "๋๊ฒฐ", "๋ฌธํ ์ค์ ", "๊ฒฝ์ง", "์ต์ข
๊ฒฐ์ "],
|
| 299 |
-
"episode_structure": "์๋ จ๊ณผ ๋๊ฒฐ์ ๋ฐ๋ณต, ์ ์ง์ ๊ฒฝ์ง ์์น"
|
| 300 |
-
},
|
| 301 |
-
"๋ฏธ์คํฐ๋ฆฌ": {
|
| 302 |
-
"key_elements": ["๋จ์", "์ถ๋ฆฌ", "๋ฐ์ ", "์์คํ์ค", "์ง์ค"],
|
| 303 |
-
"popular_tropes": ["ํ์ ", "์ฐ์ ์ฌ๊ฑด", "๊ณผ๊ฑฐ์ ๋น๋ฐ", "๋ณต์๊ทน", "์ฌ๋ฆฌ์ "],
|
| 304 |
-
"must_have": ["๋ณต์ ", "๋ถ์ ์ฒญ์ด", "๋
ผ๋ฆฌ์ ์ถ๋ฆฌ", "์ถฉ๊ฒฉ ๋ฐ์ ", "ํด๊ฒฐ"],
|
| 305 |
-
"episode_structure": "๋จ์์ ์ ์ง์ ๊ณต๊ฐ, ๊ธด์ฅ๊ฐ ์์น"
|
| 306 |
-
},
|
| 307 |
-
"๋ผ์ดํธ๋
ธ๋ฒจ": {
|
| 308 |
-
"key_elements": ["ํ์", "์ผ์", "์ฝ๋ฏธ๋", "๋ชจ์", "๋ฐฐํ"],
|
| 309 |
-
"popular_tropes": ["์ด์ธ๊ณ", "ํ๋ ", "์ธค๋ฐ๋ ", "์นํธ", "๊ธธ๋"],
|
| 310 |
-
"must_have": ["๊ฐ๋ฒผ์ด ๋ฌธ์ฒด", "์ ๋จธ", "์บ๋ฆญํฐ์ฑ", "์ผ๋ฌ์คํธ์ ๋ฌ์ฌ", "์์์ง๊ป"],
|
| 311 |
-
"episode_structure": "์ํผ์๋ ์ค์ฌ, ๊ฐ๊ทธ์ ์ง์ง์ ๊ท ํ"
|
| 312 |
-
}
|
| 313 |
-
}
|
| 314 |
-
|
| 315 |
-
# Episode hooks by genre
|
| 316 |
-
EPISODE_HOOKS = {
|
| 317 |
-
"๋ก๋งจ์ค": [
|
| 318 |
-
"๊ทธ์ ์
์ ์ด ๋ด ๊ท์ ๋ฟ์ ๋ฏ ๊ฐ๊น์์ก๋ค.",
|
| 319 |
-
"'์ฌ์ค... ๋๋ฅผ ์ฒ์ ๋ณธ ์๊ฐ๋ถํฐ...'",
|
| 320 |
-
"๊ทธ๋, ์์์น ๋ชปํ ์ฌ๋์ด ๋ฌธ์ ์ด๊ณ ๋ค์ด์๋ค.",
|
| 321 |
-
"๋ฉ์์ง๋ฅผ ํ์ธํ ์๊ฐ, ์ฌ์ฅ์ด ๋ฉ์ถ ๊ฒ ๊ฐ์๋ค."
|
| 322 |
-
],
|
| 323 |
-
"๋กํ": [
|
| 324 |
-
"๊ทธ ์๊ฐ, ์์์๋ ์๋ ์ธ๋ฌผ์ด ๋ํ๋ฌ๋ค.",
|
| 325 |
-
"'ํํ, ๊ณ์ฝ์ ํ๊ธฐํ๊ฒ ์ต๋๋ค.'",
|
| 326 |
-
"๊ฒ์ ์ค๋ผ๊ฐ ๊ทธ๋ฅผ ๊ฐ์ธ๋ฉฐ ๋๋น์ด ๋ณํ๋ค.",
|
| 327 |
-
"ํ๊ท ์ ์๋ ๋ชฐ๋๋ ์ง์ค์ด ๋๋ฌ๋ฌ๋ค."
|
| 328 |
-
],
|
| 329 |
-
"ํํ์ง": [
|
| 330 |
-
"[์๋ก์ด ์คํฌ์ ํ๋ํ์ต๋๋ค!]",
|
| 331 |
-
"๋์ ์ต์ฌ๋ถ์์ ๋ฐ๊ฒฌํ ๊ฒ์...",
|
| 332 |
-
"'์ด๊ฑด... SSS๊ธ ์์ดํ
์ด๋ค!'",
|
| 333 |
-
"์์คํ
์ฐฝ์ ๋ฌ ๊ฒฝ๊ณ ๋ฉ์์ง๋ฅผ ๋ณด๊ณ ๊ฒฝ์
ํ๋ค."
|
| 334 |
-
],
|
| 335 |
-
"ํํ": [
|
| 336 |
-
"ํ๋ฒํ ํ์์ธ ์ค ์์๋ ๊ทธ์ ๋์ด ๋ถ๊ฒ ๋น๋ฌ๋ค.",
|
| 337 |
-
"๊ฐ์๊ธฐ ํ๋์ ๊ฑฐ๋ํ ๊ท ์ด์ด ์๊ฒผ๋ค.",
|
| 338 |
-
"'๋น์ ๋... ๋ฅ๋ ฅ์์๊ตฐ์.'",
|
| 339 |
-
"ํธ๋ํฐ์ ๋ฌ ๊ธด๊ธ ์ฌ๋ ๋ฌธ์๋ฅผ ๋ณด๊ณ ์ผ์ด๋ถ์๋ค."
|
| 340 |
-
],
|
| 341 |
-
"๋ฌดํ": [
|
| 342 |
-
"๊ทธ์ ๊ฒ์์ ํ๋ฌ๋์จ ๊ฒ๊ธฐ๋ฅผ ๋ณด๊ณ ๋ชจ๋๊ฐ ๊ฒฝ์
ํ๋ค.",
|
| 343 |
-
"'์ด๊ฒ์ด... ์ ์ค์ ์ฒ๋ง์ ๊ณต?!'",
|
| 344 |
-
"ํผ๋ฅผ ํ ํ๋ฉฐ ์ฐ๋ฌ์ง ์ฌ๋ถ๊ฐ ๋ง์ง๋ง์ผ๋ก ๋จ๊ธด ๋ง์...",
|
| 345 |
-
"๊ทธ๋, ํ๋์์ ํ ์ค๊ธฐ ๋น์ด ๋ด๋ ค์๋ค."
|
| 346 |
-
],
|
| 347 |
-
"๋ฏธ์คํฐ๋ฆฌ": [
|
| 348 |
-
"๊ทธ๋ฆฌ๊ณ ์์ฒด ์์์ ๋ฐ๊ฒฌ๋ ๊ฒ์...",
|
| 349 |
-
"'๋ฒ์ธ์ ์ด ์์ ์์ต๋๋ค.'",
|
| 350 |
-
"์ผ๊ธฐ์ฅ์ ๋ง์ง๋ง ํ์ด์ง๋ฅผ ๋๊ธฐ์...",
|
| 351 |
-
"CCTV์ ์ฐํ ๊ทธ ์๊ฐ, ๋ชจ๋ ๊ฒ์ด ๋ค๋ฐ๋์๋ค."
|
| 352 |
-
],
|
| 353 |
-
"๋ผ์ดํธ๋
ธ๋ฒจ": [
|
| 354 |
-
"'์ ๋ฐฐ! ์ฌ์ค ์ ... ๋ง์์ด์์!'",
|
| 355 |
-
"์ ํ์์ ์ ์ฒด๋ ๋ค๋ฆ ์๋...",
|
| 356 |
-
"๊ทธ๋
์ ๊ฐ๋ฐฉ์์ ๋จ์ด์ง ๊ฒ์ ๋ณด๊ณ ๊ฒฝ์
ํ๋ค.",
|
| 357 |
-
"'์ด๋ผ? ์ด๊ฑฐ... ๊ฒ์ ์์ดํ
์ด ํ์ค์?'"
|
| 358 |
-
]
|
| 359 |
-
}
|
| 360 |
-
|
| 361 |
-
# --- Global variables ---
|
| 362 |
-
db_lock = threading.Lock()
|
| 363 |
-
current_state = {
|
| 364 |
-
"selected_words": [],
|
| 365 |
-
"genre": "",
|
| 366 |
-
"loglines": [],
|
| 367 |
-
"evaluations": [],
|
| 368 |
-
"ai_selected": "",
|
| 369 |
-
"ai_reason": "",
|
| 370 |
-
"user_prompt": ""
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
# --- Data classes ---
|
| 374 |
-
@dataclass
|
| 375 |
-
class StoryStructure:
|
| 376 |
-
"""Story structure for web novel"""
|
| 377 |
-
title: str = ""
|
| 378 |
-
genre: str = ""
|
| 379 |
-
synopsis: str = ""
|
| 380 |
-
characters: Dict[str, Dict[str, Any]] = field(default_factory=dict)
|
| 381 |
-
world_setting: str = ""
|
| 382 |
-
power_system: Dict[str, Any] = field(default_factory=dict)
|
| 383 |
-
episode_outlines: Dict[int, Dict[str, str]] = field(default_factory=dict) # 40ํ ๊ตฌ์ฑ
|
| 384 |
-
key_events: List[Dict[str, Any]] = field(default_factory=list)
|
| 385 |
-
climax_points: List[int] = field(default_factory=list) # ํด๋ผ์ด๋งฅ์ค ํ์
|
| 386 |
-
|
| 387 |
-
@dataclass
|
| 388 |
-
class NovelSession:
|
| 389 |
-
"""Session data for a novel"""
|
| 390 |
-
session_id: str
|
| 391 |
-
user_id: str
|
| 392 |
-
genre: str
|
| 393 |
-
title: str
|
| 394 |
-
story_structure: StoryStructure
|
| 395 |
-
current_episode: int = 0
|
| 396 |
-
created_at: str = ""
|
| 397 |
-
updated_at: str = ""
|
| 398 |
-
status: str = "active" # active, completed, paused
|
| 399 |
-
|
| 400 |
-
# --- Database schema update ---
|
| 401 |
-
class WebNovelDatabase:
|
| 402 |
-
"""Database management for web novel system"""
|
| 403 |
-
@staticmethod
|
| 404 |
-
def init_db():
|
| 405 |
-
with sqlite3.connect(DB_PATH) as conn:
|
| 406 |
-
conn.execute("PRAGMA journal_mode=WAL")
|
| 407 |
-
cursor = conn.cursor()
|
| 408 |
-
|
| 409 |
-
# Users table
|
| 410 |
-
cursor.execute('''
|
| 411 |
-
CREATE TABLE IF NOT EXISTS users (
|
| 412 |
-
user_id TEXT PRIMARY KEY,
|
| 413 |
-
username TEXT NOT NULL,
|
| 414 |
-
email TEXT,
|
| 415 |
-
created_at TEXT DEFAULT (datetime('now')),
|
| 416 |
-
last_login TEXT DEFAULT (datetime('now'))
|
| 417 |
-
)
|
| 418 |
-
''')
|
| 419 |
-
|
| 420 |
-
# Sessions table with user ownership
|
| 421 |
-
cursor.execute('''
|
| 422 |
-
CREATE TABLE IF NOT EXISTS sessions (
|
| 423 |
-
session_id TEXT PRIMARY KEY,
|
| 424 |
-
user_id TEXT NOT NULL,
|
| 425 |
-
genre TEXT NOT NULL,
|
| 426 |
-
title TEXT,
|
| 427 |
-
logline TEXT,
|
| 428 |
-
story_structure TEXT, -- JSON
|
| 429 |
-
current_episode INTEGER DEFAULT 0,
|
| 430 |
-
total_episodes INTEGER DEFAULT 40,
|
| 431 |
-
created_at TEXT DEFAULT (datetime('now')),
|
| 432 |
-
updated_at TEXT DEFAULT (datetime('now')),
|
| 433 |
-
status TEXT DEFAULT 'active',
|
| 434 |
-
FOREIGN KEY (user_id) REFERENCES users(user_id)
|
| 435 |
-
)
|
| 436 |
-
''')
|
| 437 |
-
|
| 438 |
-
# Episodes table
|
| 439 |
-
cursor.execute('''
|
| 440 |
-
CREATE TABLE IF NOT EXISTS episodes (
|
| 441 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 442 |
-
session_id TEXT NOT NULL,
|
| 443 |
-
episode_number INTEGER NOT NULL,
|
| 444 |
-
title TEXT,
|
| 445 |
-
content TEXT,
|
| 446 |
-
hook TEXT,
|
| 447 |
-
word_count INTEGER DEFAULT 0,
|
| 448 |
-
created_at TEXT DEFAULT (datetime('now')),
|
| 449 |
-
FOREIGN KEY (session_id) REFERENCES sessions(session_id),
|
| 450 |
-
UNIQUE(session_id, episode_number)
|
| 451 |
-
)
|
| 452 |
-
''')
|
| 453 |
-
|
| 454 |
-
# Story planning table
|
| 455 |
-
cursor.execute('''
|
| 456 |
-
CREATE TABLE IF NOT EXISTS story_plans (
|
| 457 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 458 |
-
session_id TEXT NOT NULL,
|
| 459 |
-
selected_words TEXT, -- JSON
|
| 460 |
-
logline TEXT,
|
| 461 |
-
synopsis TEXT,
|
| 462 |
-
character_profiles TEXT, -- JSON
|
| 463 |
-
episode_outlines TEXT, -- JSON
|
| 464 |
-
created_at TEXT DEFAULT (datetime('now')),
|
| 465 |
-
FOREIGN KEY (session_id) REFERENCES sessions(session_id)
|
| 466 |
-
)
|
| 467 |
-
''')
|
| 468 |
-
|
| 469 |
-
conn.commit()
|
| 470 |
-
|
| 471 |
-
@staticmethod
|
| 472 |
-
@contextmanager
|
| 473 |
-
def get_db():
|
| 474 |
-
with db_lock:
|
| 475 |
-
conn = sqlite3.connect(DB_PATH, timeout=30.0)
|
| 476 |
-
conn.row_factory = sqlite3.Row
|
| 477 |
-
try:
|
| 478 |
-
yield conn
|
| 479 |
-
finally:
|
| 480 |
-
conn.close()
|
| 481 |
-
|
| 482 |
-
@staticmethod
|
| 483 |
-
def create_or_update_user(user_id: str, username: str, email: str = None):
|
| 484 |
-
with WebNovelDatabase.get_db() as conn:
|
| 485 |
-
conn.cursor().execute('''
|
| 486 |
-
INSERT INTO users (user_id, username, email)
|
| 487 |
-
VALUES (?, ?, ?)
|
| 488 |
-
ON CONFLICT(user_id) DO UPDATE SET
|
| 489 |
-
username = excluded.username,
|
| 490 |
-
email = excluded.email,
|
| 491 |
-
last_login = datetime('now')
|
| 492 |
-
''', (user_id, username, email))
|
| 493 |
-
conn.commit()
|
| 494 |
-
|
| 495 |
-
@staticmethod
|
| 496 |
-
def create_session(user_id: str, genre: str, title: str = None, logline: str = None) -> str:
|
| 497 |
-
session_id = hashlib.md5(f"{user_id}{genre}{datetime.now()}".encode()).hexdigest()
|
| 498 |
-
with WebNovelDatabase.get_db() as conn:
|
| 499 |
-
conn.cursor().execute(
|
| 500 |
-
'''INSERT INTO sessions (session_id, user_id, genre, title, logline)
|
| 501 |
-
VALUES (?, ?, ?, ?, ?)''',
|
| 502 |
-
(session_id, user_id, genre, title, logline)
|
| 503 |
-
)
|
| 504 |
-
conn.commit()
|
| 505 |
-
return session_id
|
| 506 |
-
|
| 507 |
-
@staticmethod
|
| 508 |
-
def get_user_sessions(user_id: str) -> List[Dict]:
|
| 509 |
-
with WebNovelDatabase.get_db() as conn:
|
| 510 |
-
rows = conn.cursor().execute(
|
| 511 |
-
'''SELECT * FROM sessions WHERE user_id = ?
|
| 512 |
-
ORDER BY updated_at DESC''',
|
| 513 |
-
(user_id,)
|
| 514 |
-
).fetchall()
|
| 515 |
-
return [dict(row) for row in rows]
|
| 516 |
-
|
| 517 |
-
@staticmethod
|
| 518 |
-
def get_session(session_id: str) -> Optional[Dict]:
|
| 519 |
-
with WebNovelDatabase.get_db() as conn:
|
| 520 |
-
row = conn.cursor().execute(
|
| 521 |
-
'SELECT * FROM sessions WHERE session_id = ?',
|
| 522 |
-
(session_id,)
|
| 523 |
-
).fetchone()
|
| 524 |
-
return dict(row) if row else None
|
| 525 |
-
|
| 526 |
-
@staticmethod
|
| 527 |
-
def save_story_structure(session_id: str, story_structure: StoryStructure):
|
| 528 |
-
with WebNovelDatabase.get_db() as conn:
|
| 529 |
-
conn.cursor().execute(
|
| 530 |
-
'''UPDATE sessions
|
| 531 |
-
SET story_structure = ?, title = ?, updated_at = datetime('now')
|
| 532 |
-
WHERE session_id = ?''',
|
| 533 |
-
(json.dumps(asdict(story_structure)), story_structure.title, session_id)
|
| 534 |
-
)
|
| 535 |
-
conn.commit()
|
| 536 |
-
|
| 537 |
-
@staticmethod
|
| 538 |
-
def save_episode(session_id: str, episode_num: int, title: str,
|
| 539 |
-
content: str, hook: str):
|
| 540 |
-
word_count = len(content.split()) if content else 0
|
| 541 |
-
with WebNovelDatabase.get_db() as conn:
|
| 542 |
-
cursor = conn.cursor()
|
| 543 |
-
cursor.execute('''
|
| 544 |
-
INSERT INTO episodes (session_id, episode_number, title,
|
| 545 |
-
content, hook, word_count)
|
| 546 |
-
VALUES (?, ?, ?, ?, ?, ?)
|
| 547 |
-
ON CONFLICT(session_id, episode_number)
|
| 548 |
-
DO UPDATE SET title=?, content=?, hook=?, word_count=?
|
| 549 |
-
''', (session_id, episode_num, title, content, hook, word_count,
|
| 550 |
-
title, content, hook, word_count))
|
| 551 |
-
|
| 552 |
-
# Update session progress
|
| 553 |
-
cursor.execute('''
|
| 554 |
-
UPDATE sessions
|
| 555 |
-
SET current_episode = ?, updated_at = datetime('now')
|
| 556 |
-
WHERE session_id = ?
|
| 557 |
-
''', (episode_num, session_id))
|
| 558 |
-
|
| 559 |
-
conn.commit()
|
| 560 |
-
|
| 561 |
-
@staticmethod
|
| 562 |
-
def get_episodes(session_id: str) -> List[Dict]:
|
| 563 |
-
with WebNovelDatabase.get_db() as conn:
|
| 564 |
-
rows = conn.cursor().execute(
|
| 565 |
-
'''SELECT * FROM episodes WHERE session_id = ?
|
| 566 |
-
ORDER BY episode_number''',
|
| 567 |
-
(session_id,)
|
| 568 |
-
).fetchall()
|
| 569 |
-
return [dict(row) for row in rows]
|
| 570 |
-
|
| 571 |
-
@staticmethod
|
| 572 |
-
def check_ownership(session_id: str, user_id: str) -> bool:
|
| 573 |
-
with WebNovelDatabase.get_db() as conn:
|
| 574 |
-
row = conn.cursor().execute(
|
| 575 |
-
'SELECT user_id FROM sessions WHERE session_id = ?',
|
| 576 |
-
(session_id,)
|
| 577 |
-
).fetchone()
|
| 578 |
-
return row and row['user_id'] == user_id
|
| 579 |
-
|
| 580 |
-
@staticmethod
|
| 581 |
-
def save_story_plan(session_id: str, selected_words: List[Tuple[str, str]],
|
| 582 |
-
logline: str, synopsis: str = None):
|
| 583 |
-
with WebNovelDatabase.get_db() as conn:
|
| 584 |
-
conn.cursor().execute('''
|
| 585 |
-
INSERT INTO story_plans (session_id, selected_words, logline, synopsis)
|
| 586 |
-
VALUES (?, ?, ?, ?)
|
| 587 |
-
''', (session_id, json.dumps(selected_words), logline, synopsis))
|
| 588 |
-
conn.commit()
|
| 589 |
-
|
| 590 |
-
# --- LLM Integration ---
|
| 591 |
-
class WebNovelSystem:
|
| 592 |
-
"""Web novel generation system"""
|
| 593 |
-
def __init__(self):
|
| 594 |
-
self.token = FRIENDLI_TOKEN
|
| 595 |
-
self.api_url = API_URL
|
| 596 |
-
self.model_id = MODEL_ID
|
| 597 |
-
WebNovelDatabase.init_db()
|
| 598 |
-
|
| 599 |
-
def create_headers(self):
|
| 600 |
-
return {"Authorization": f"Bearer {self.token}", "Content-Type": "application/json"}
|
| 601 |
-
|
| 602 |
-
# --- Step 1: Logline generation (from paste.txt) ---
|
| 603 |
-
def interpret_user_prompt(self, user_prompt: str) -> Dict[str, any]:
|
| 604 |
-
"""์ฌ์ฉ์์ ํ๋กฌํํธ๋ฅผ ํด์ํ์ฌ ์นดํ
๊ณ ๋ฆฌ, ๋จ์ด, ์ฅ๋ฅด ๋ฑ์ ์ถ์ถ"""
|
| 605 |
-
logger.info(f"ํ๋กฌํํธ ํด์ ์์: {user_prompt[:50]}...")
|
| 606 |
-
|
| 607 |
-
prompt = f"""๋ค์ ์ฌ์ฉ์์ ์์ฒญ์ ๋ถ์ํ์ฌ ์คํ ๋ฆฌ ์์ฑ์ ํ์ํ ์์๋ค์ ์ถ์ถํด์ฃผ์ธ์.
|
| 608 |
-
|
| 609 |
-
์ฌ์ฉ์ ์์ฒญ: "{user_prompt}"
|
| 610 |
-
|
| 611 |
-
๊ฐ๋ฅํ ์นดํ
๊ณ ๋ฆฌ: {', '.join(complete_word_list.keys())}
|
| 612 |
-
|
| 613 |
-
๋ค์ ํ์์ผ๋ก ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํด์ฃผ์ธ์:
|
| 614 |
-
|
| 615 |
-
[์ถ์ถ๋ ์์]
|
| 616 |
-
์นดํ
๊ณ ๋ฆฌ1: (์นดํ
๊ณ ๋ฆฌ๋ช
) - (๋จ์ด)
|
| 617 |
-
์นดํ
๊ณ ๋ฆฌ2: (์นดํ
๊ณ ๋ฆฌ๋ช
) - (๋จ์ด)
|
| 618 |
-
์นดํ
๊ณ ๋ฆฌ3: (์นดํ
๊ณ ๋ฆฌ๋ช
) - (๋จ์ด)
|
| 619 |
-
|
| 620 |
-
[์ฅ๋ฅด]
|
| 621 |
-
(์ถ์ถ๋ ์ฅ๋ฅด ๋๋ ์ฌ์ฉ์๊ฐ ์ํ๋ ๋ถ์๊ธฐ)
|
| 622 |
-
|
| 623 |
-
[ํน๋ณ ์ง์์ฌํญ]
|
| 624 |
-
(์ฌ์ฉ์๊ฐ ๊ฐ์กฐํ ํน๋ณํ ์๊ตฌ์ฌํญ์ด๋ ์คํ ๋ฆฌ ๋ฐฉํฅ์ฑ)
|
| 625 |
-
|
| 626 |
-
์ฃผ์์ฌํญ:
|
| 627 |
-
1. ์ฌ์ฉ์๊ฐ ๊ตฌ์ฒด์ ์ผ๋ก ์ธ๊ธํ ๋จ์ด๊ฐ ์๋ค๋ฉด ๊ทธ์ ๋ง๋ ์นดํ
๊ณ ๋ฆฌ์์ ์ ํ
|
| 628 |
-
2. ์ธ๊ธ์ด ์๋ ๋ถ๋ถ์ ๋ฌธ๋งฅ์ ๋ง์ถฐ ์ ์ ํ ์ ํ
|
| 629 |
-
3. ๊ฐ๋ฅํ ํ ๋ค์ํ ์นดํ
๊ณ ๋ฆฌ์์ ์ ํํ์ฌ ํ๋ถํ ์คํ ๋ฆฌ๊ฐ ๋๋๋ก ํจ"""
|
| 630 |
-
|
| 631 |
-
try:
|
| 632 |
-
result = self.call_llm_sync([{"role": "user", "content": prompt}], "planner")
|
| 633 |
-
logger.info("LLM ์๋ต ์์ ์๋ฃ")
|
| 634 |
-
|
| 635 |
-
# Parse result
|
| 636 |
-
lines = result.split('\n')
|
| 637 |
-
extracted = {
|
| 638 |
-
"words": [],
|
| 639 |
-
"genre": "",
|
| 640 |
-
"special_instructions": ""
|
| 641 |
-
}
|
| 642 |
-
|
| 643 |
-
current_section = None
|
| 644 |
-
for line in lines:
|
| 645 |
-
line = line.strip()
|
| 646 |
-
if '[์ถ์ถ๋ ์์]' in line:
|
| 647 |
-
current_section = 'elements'
|
| 648 |
-
elif '[์ฅ๋ฅด]' in line:
|
| 649 |
-
current_section = 'genre'
|
| 650 |
-
elif '[ํน๋ณ ์ง์์ฌํญ]' in line:
|
| 651 |
-
current_section = 'instructions'
|
| 652 |
-
elif line and current_section:
|
| 653 |
-
if current_section == 'elements' and '์นดํ
๊ณ ๋ฆฌ' in line and ':' in line:
|
| 654 |
-
parts = line.split(':', 1)[1].strip()
|
| 655 |
-
if ' - ' in parts:
|
| 656 |
-
category, word = parts.split(' - ', 1)
|
| 657 |
-
extracted["words"].append((category.strip(), word.strip()))
|
| 658 |
-
logger.info(f"์ถ์ถ๋ ๋จ์ด: {category.strip()} - {word.strip()}")
|
| 659 |
-
elif current_section == 'genre':
|
| 660 |
-
extracted["genre"] = line
|
| 661 |
-
logger.info(f"์ถ์ถ๋ ์ฅ๋ฅด: {line}")
|
| 662 |
-
elif current_section == 'instructions':
|
| 663 |
-
extracted["special_instructions"] += line + " "
|
| 664 |
-
|
| 665 |
-
logger.info(f"ํ๋กฌํํธ ํด์ ์๋ฃ: {len(extracted['words'])}๊ฐ ๋จ์ด ์ถ์ถ")
|
| 666 |
-
return extracted
|
| 667 |
-
|
| 668 |
-
except Exception as e:
|
| 669 |
-
logger.error(f"ํ๋กฌํํธ ํด์ ์ค๋ฅ: {str(e)}", exc_info=True)
|
| 670 |
-
raise
|
| 671 |
-
|
| 672 |
-
def generate_loglines_and_evaluate(self, categories_words: List[Tuple[str, str]]) -> Dict[str, any]:
|
| 673 |
-
"""10๊ฐ์ ๋ก๊ทธ๋ผ์ธ์ ์์ฑํ๊ณ ํ๊ฐํ์ฌ ์ต์ ์ ๊ฒ์ ์ ํ"""
|
| 674 |
-
logger.info(f"๋ก๊ทธ๋ผ์ธ ์์ฑ ์์ - ๋จ์ด: {categories_words}")
|
| 675 |
-
|
| 676 |
-
prompt = f"""๋ค์ 3๊ฐ ์นดํ
๊ณ ๋ฆฌ์ ๋จ์ด๋ค์ ๋ชจ๋ ์ฌ์ฉํ์ฌ ์๋ก ๋ค๋ฅธ ๊ด์ ๊ณผ ์ฅ๋ฅด์ ๋ก๊ทธ๋ผ์ธ์ 10๊ฐ ์์ฑํด์ฃผ์ธ์.
|
| 677 |
-
|
| 678 |
-
์นดํ
๊ณ ๋ฆฌ์ ์ ํ๋ ๋จ์ด:
|
| 679 |
-
1. {categories_words[0][0]}: {categories_words[0][1]}
|
| 680 |
-
2. {categories_words[1][0]}: {categories_words[1][1]}
|
| 681 |
-
3. {categories_words[2][0]}: {categories_words[2][1]}
|
| 682 |
-
|
| 683 |
-
์๊ตฌ์ฌํญ:
|
| 684 |
-
1. ๊ฐ ๋ก๊ทธ๋ผ์ธ์ 1-2๋ฌธ์ฅ์ผ๋ก ์์ฑ
|
| 685 |
-
2. 3๊ฐ ๋จ์ด๋ฅผ ๋ชจ๋ ์์ฐ์ค๋ฝ๊ฒ ํฌํจ
|
| 686 |
-
3. ์๋ก ๋ค๋ฅธ ์ฅ๋ฅด์ ํค์ผ๋ก ์์ฑ (์ค๋ฆด๋ฌ, ๋ก๋งจ์ค, ์ฝ๋ฏธ๋, ํธ๋ฌ, SF, ํํ์ง, ๋ฏธ์คํฐ๋ฆฌ ๋ฑ)
|
| 687 |
-
4. ๋
์ฐฝ์ ์ด๊ณ ํฅ๋ฏธ๋ก์ด ๊ด์ ์ ์
|
| 688 |
-
|
| 689 |
-
๊ทธ ๋ค์, ๊ฐ ๋ก๊ทธ๋ผ์ธ์ ๋ค์ 4๊ฐ์ง ๊ธฐ์ค์ผ๋ก ํ๊ฐํด์ฃผ์ธ์ (๊ฐ 10์ ๋ง์ ):
|
| 690 |
-
- ๋
์ฐฝ์ฑ: ๊ธฐ์กด ์ํ๊ณผ์ ์ฐจ๋ณ์ฑ, ์ ์ ํจ
|
| 691 |
-
- ํฅ๋ฏธ๋: ๊ด๊ฐ์ ํธ๊ธฐ์ฌ์ ์ ๋ฐํ๋ ์ ๋
|
| 692 |
-
- ์์ฌ์ฑ: ์ด์ผ๊ธฐ๋ก ๋ฐ์ ์ํฌ ์ ์๋ ์ ์ฌ๋ ฅ
|
| 693 |
-
- ๊ฐ์ฐ์ฑ: ๋
ผ๋ฆฌ์ ํ๋น์ฑ๊ณผ ํ์ค์ฑ
|
| 694 |
-
|
| 695 |
-
๋ฐ๋์ ์๋ ํ์์ผ๋ก ์์ฑํด์ฃผ์ธ์:
|
| 696 |
-
|
| 697 |
-
[๋ก๊ทธ๋ผ์ธ ์์ฑ]
|
| 698 |
-
๋ก๊ทธ๋ผ์ธ 1: (๋ด์ฉ)
|
| 699 |
-
๋ก๊ทธ๋ผ์ธ 2: (๋ด์ฉ)
|
| 700 |
-
๋ก๊ทธ๋ผ์ธ 3: (๋ด์ฉ)
|
| 701 |
-
๋ก๊ทธ๋ผ์ธ 4: (๋ด์ฉ)
|
| 702 |
-
๋ก๊ทธ๋ผ์ธ 5: (๋ด์ฉ)
|
| 703 |
-
๋ก๊ทธ๋ผ์ธ 6: (๋ด์ฉ)
|
| 704 |
-
๋ก๊ทธ๋ผ์ธ 7: (๋ด์ฉ)
|
| 705 |
-
๋ก๊ทธ๋ผ์ธ 8: (๋ด์ฉ)
|
| 706 |
-
๋ก๊ทธ๋ผ์ธ 9: (๋ด์ฉ)
|
| 707 |
-
๋ก๊ทธ๋ผ์ธ 10: (๋ด์ฉ)
|
| 708 |
-
|
| 709 |
-
[ํ๊ฐ ๊ฒฐ๊ณผ]
|
| 710 |
-
๋ก๊ทธ๋ผ์ธ 1: ๋
์ฐฝ์ฑ(X/10), ํฅ๋ฏธ๋(X/10), ์์ฌ์ฑ(X/10), ๊ฐ์ฐ์ฑ(X/10), ์ด์ (XX/40)
|
| 711 |
-
๋ก๊ทธ๋ผ์ธ 2: ๋
์ฐฝ์ฑ(X/10), ํฅ๋ฏธ๋(X/10), ์์ฌ์ฑ(X/10), ๊ฐ์ฐ์ฑ(X/10), ์ด์ (XX/40)
|
| 712 |
-
... (๋ชจ๋ ๋ก๊ทธ๋ผ์ธ ํ๊ฐ)
|
| 713 |
-
|
| 714 |
-
[์ต์ข
์ ํ]
|
| 715 |
-
์ ํ๋ ๋ก๊ทธ๋ผ์ธ: (๊ฐ์ฅ ๋์ ์ ์๋ฅผ ๋ฐ์ ๋ก๊ทธ๋ผ์ธ ๋ฒํธ์ ๋ด์ฉ)
|
| 716 |
-
|
| 717 |
-
[์ ํ ์ด์ ]
|
| 718 |
-
(์ ์ด ๋ก๊ทธ๋ผ์ธ์ด ๊ฐ์ฅ ์ข์์ง ๊ตฌ์ฒด์ ์ผ๋ก ์ค๋ช
)"""
|
| 719 |
-
|
| 720 |
-
try:
|
| 721 |
-
logger.info("LLM ํธ์ถ ์ค...")
|
| 722 |
-
result = self.call_llm_sync([{"role": "user", "content": prompt}], "planner")
|
| 723 |
-
logger.info("LLM ์๋ต ์์ ์๋ฃ")
|
| 724 |
-
|
| 725 |
-
# Parse result
|
| 726 |
-
sections = {
|
| 727 |
-
"loglines": [],
|
| 728 |
-
"evaluations": [],
|
| 729 |
-
"selected": "",
|
| 730 |
-
"reason": ""
|
| 731 |
-
}
|
| 732 |
-
|
| 733 |
-
lines = result.split('\n')
|
| 734 |
-
current_section = None
|
| 735 |
-
|
| 736 |
-
for line in lines:
|
| 737 |
-
line = line.strip()
|
| 738 |
-
|
| 739 |
-
if '[๋ก๊ทธ๋ผ์ธ ์์ฑ]' in line:
|
| 740 |
-
current_section = 'loglines'
|
| 741 |
-
logger.info("๋ก๊ทธ๋ผ์ธ ์น์
ํ์ฑ ์์")
|
| 742 |
-
elif '[ํ๊ฐ ๊ฒฐ๊ณผ]' in line:
|
| 743 |
-
current_section = 'evaluations'
|
| 744 |
-
logger.info("ํ๊ฐ ์น์
ํ์ฑ ์์")
|
| 745 |
-
elif '[์ต์ข
์ ํ]' in line:
|
| 746 |
-
current_section = 'selected'
|
| 747 |
-
logger.info("์ต์ข
์ ํ ์น์
ํ์ฑ ์์")
|
| 748 |
-
elif '[์ ํ ์ด์ ]' in line:
|
| 749 |
-
current_section = 'reason'
|
| 750 |
-
elif line and current_section:
|
| 751 |
-
if current_section == 'loglines' and line.startswith('๋ก๊ทธ๋ผ์ธ'):
|
| 752 |
-
parts = line.split(':', 1)
|
| 753 |
-
if len(parts) == 2:
|
| 754 |
-
sections['loglines'].append(parts[1].strip())
|
| 755 |
-
elif current_section == 'evaluations' and line.startswith('๋ก๊ทธ๋ผ์ธ'):
|
| 756 |
-
sections['evaluations'].append(line)
|
| 757 |
-
elif current_section == 'selected':
|
| 758 |
-
if '์ ํ๋ ๋ก๊ทธ๋ผ์ธ:' in line:
|
| 759 |
-
sections['selected'] = line.replace('์ ํ๋ ๋ก๊ทธ๋ผ์ธ:', '').strip()
|
| 760 |
-
else:
|
| 761 |
-
sections['selected'] += ' ' + line
|
| 762 |
-
elif current_section == 'reason':
|
| 763 |
-
sections['reason'] += line + ' '
|
| 764 |
-
|
| 765 |
-
logger.info(f"ํ์ฑ ์๋ฃ - ๋ก๊ทธ๋ผ์ธ {len(sections['loglines'])}๊ฐ ์์ฑ")
|
| 766 |
-
return sections
|
| 767 |
-
|
| 768 |
-
except Exception as e:
|
| 769 |
-
logger.error(f"๋ก๊ทธ๋ผ๏ฟฝ๏ฟฝ ์์ฑ ์ค๋ฅ: {str(e)}", exc_info=True)
|
| 770 |
-
raise
|
| 771 |
-
|
| 772 |
-
def generate_10_loglines_with_prompt(self, user_prompt: str, categories_words: List[Tuple[str, str]],
|
| 773 |
-
genre: str, special_instructions: str) -> Dict[str, any]:
|
| 774 |
-
"""์ฌ์ฉ์ ํ๋กฌํํธ๋ฅผ ๋ฐ์ํ์ฌ 10๊ฐ์ ๋ก๊ทธ๋ผ์ธ์ ์์ฑํ๊ณ ํ๊ฐ"""
|
| 775 |
-
prompt = f"""์ฌ์ฉ์์ ๋ค์ ์์ฒญ์ ๋ฐ์ํ์ฌ ๋ก๊ทธ๋ผ์ธ์ ์์ฑํด์ฃผ์ธ์.
|
| 776 |
-
|
| 777 |
-
์ฌ์ฉ์ ์์ฒญ: "{user_prompt}"
|
| 778 |
-
|
| 779 |
-
์ถ์ถ๋ ์์:
|
| 780 |
-
1. {categories_words[0][0]}: {categories_words[0][1]}
|
| 781 |
-
2. {categories_words[1][0]}: {categories_words[1][1]}
|
| 782 |
-
3. {categories_words[2][0]}: {categories_words[2][1]}
|
| 783 |
-
|
| 784 |
-
์ฅ๋ฅด/๋ถ์๊ธฐ: {genre}
|
| 785 |
-
ํน๋ณ ์ง์์ฌํญ: {special_instructions}
|
| 786 |
-
|
| 787 |
-
์ ์์๋ค์ ๋ชจ๋ ๋ฐ์ํ์ฌ ์๋ก ๋ค๋ฅธ ๊ด์ ๊ณผ ์คํ์ผ์ ๋ก๊ทธ๋ผ์ธ์ 10๊ฐ ์์ฑํด์ฃผ์ธ์.
|
| 788 |
-
|
| 789 |
-
์๊ตฌ์ฌํญ:
|
| 790 |
-
1. ๊ฐ ๋ก๊ทธ๋ผ์ธ์ 1-2๋ฌธ์ฅ์ผ๋ก ์์ฑ
|
| 791 |
-
2. 3๊ฐ ๋จ์ด๋ฅผ ๋ชจ๋ ์์ฐ์ค๋ฝ๊ฒ ํฌํจ
|
| 792 |
-
3. ์ฌ์ฉ์์ ์์ฒญ ์๋๋ฅผ ์ถฉ์คํ ๋ฐ์
|
| 793 |
-
4. ๋ค์ํ ํด์๊ณผ ์ ๊ทผ์ผ๋ก ์ฐจ๋ณํ
|
| 794 |
-
|
| 795 |
-
๊ทธ ๋ค์, ๊ฐ ๋ก๊ทธ๋ผ์ธ์ ๋ค์ 4๊ฐ์ง ๊ธฐ์ค์ผ๋ก ํ๊ฐํด์ฃผ์ธ์ (๊ฐ 10์ ๋ง์ ):
|
| 796 |
-
- ๋
์ฐฝ์ฑ: ๊ธฐ์กด ์ํ๊ณผ์ ์ฐจ๋ณ์ฑ, ์ ์ ํจ
|
| 797 |
-
- ํฅ๋ฏธ๋: ๊ด๊ฐ์ ํธ๊ธฐ์ฌ์ ์ ๋ฐํ๋ ์ ๋
|
| 798 |
-
- ์์ฌ์ฑ: ์ด์ผ๊ธฐ๋ก ๋ฐ์ ์ํฌ ์ ์๋ ์ ์ฌ๋ ฅ
|
| 799 |
-
- ๊ฐ์ฐ์ฑ: ๋
ผ๋ฆฌ์ ํ๋น์ฑ๊ณผ ํ์ค์ฑ
|
| 800 |
-
|
| 801 |
-
๋ฐ๋์ ์๋ ํ์์ผ๋ก ์์ฑํด์ฃผ์ธ์:
|
| 802 |
-
|
| 803 |
-
[๋ก๊ทธ๋ผ์ธ ์์ฑ]
|
| 804 |
-
๋ก๊ทธ๋ผ์ธ 1: (๋ด์ฉ)
|
| 805 |
-
๋ก๊ทธ๋ผ์ธ 2: (๋ด์ฉ)
|
| 806 |
-
... (10๊ฐ๊น์ง)
|
| 807 |
-
|
| 808 |
-
[ํ๊ฐ ๊ฒฐ๊ณผ]
|
| 809 |
-
๋ก๊ทธ๋ผ์ธ 1: ๋
์ฐฝ์ฑ(X/10), ํฅ๋ฏธ๋(X/10), ์์ฌ์ฑ(X/10), ๊ฐ์ฐ์ฑ(X/10), ์ด์ (XX/40)
|
| 810 |
-
... (๋ชจ๋ ๋ก๊ทธ๋ผ์ธ ํ๊ฐ)
|
| 811 |
-
|
| 812 |
-
[์ต์ข
์ ํ]
|
| 813 |
-
์ ํ๋ ๋ก๊ทธ๋ผ์ธ: (๊ฐ์ฅ ๋์ ์ ์๋ฅผ ๋ฐ์ ๋ก๊ทธ๋ผ์ธ ๋ฒํธ์ ๋ด์ฉ)
|
| 814 |
-
|
| 815 |
-
[์ ํ ์ด์ ]
|
| 816 |
-
(์ ์ด ๋ก๊ทธ๋ผ์ธ์ด ๊ฐ์ฅ ์ข์์ง ๊ตฌ์ฒด์ ์ผ๋ก ์ค๋ช
)"""
|
| 817 |
-
|
| 818 |
-
result = self.call_llm_sync([{"role": "user", "content": prompt}], "planner")
|
| 819 |
-
|
| 820 |
-
# Parse result (same as generate_loglines_and_evaluate)
|
| 821 |
-
sections = {
|
| 822 |
-
"loglines": [],
|
| 823 |
-
"evaluations": [],
|
| 824 |
-
"selected": "",
|
| 825 |
-
"reason": ""
|
| 826 |
-
}
|
| 827 |
-
|
| 828 |
-
lines = result.split('\n')
|
| 829 |
-
current_section = None
|
| 830 |
-
|
| 831 |
-
for line in lines:
|
| 832 |
-
line = line.strip()
|
| 833 |
-
|
| 834 |
-
if '[๋ก๊ทธ๋ผ์ธ ์์ฑ]' in line:
|
| 835 |
-
current_section = 'loglines'
|
| 836 |
-
elif '[ํ๊ฐ ๊ฒฐ๊ณผ]' in line:
|
| 837 |
-
current_section = 'evaluations'
|
| 838 |
-
elif '[์ต์ข
์ ํ]' in line:
|
| 839 |
-
current_section = 'selected'
|
| 840 |
-
elif '[์ ํ ์ด์ ]' in line:
|
| 841 |
-
current_section = 'reason'
|
| 842 |
-
elif line and current_section:
|
| 843 |
-
if current_section == 'loglines' and line.startswith('๋ก๊ทธ๋ผ์ธ'):
|
| 844 |
-
parts = line.split(':', 1)
|
| 845 |
-
if len(parts) == 2:
|
| 846 |
-
sections['loglines'].append(parts[1].strip())
|
| 847 |
-
elif current_section == 'evaluations' and line.startswith('๋ก๊ทธ๋ผ์ธ'):
|
| 848 |
-
sections['evaluations'].append(line)
|
| 849 |
-
elif current_section == 'selected':
|
| 850 |
-
if '์ ํ๋ ๋ก๊ทธ๋ผ์ธ:' in line:
|
| 851 |
-
sections['selected'] = line.replace('์ ํ๋ ๋ก๊ทธ๋ผ์ธ:', '').strip()
|
| 852 |
-
else:
|
| 853 |
-
sections['selected'] += ' ' + line
|
| 854 |
-
elif current_section == 'reason':
|
| 855 |
-
sections['reason'] += line + ' '
|
| 856 |
-
|
| 857 |
-
return sections
|
| 858 |
-
|
| 859 |
-
def generate_story_from_prompt(self, user_prompt: str) -> Dict[str, any]:
|
| 860 |
-
"""์ฌ์ฉ์ ํ๋กฌํํธ๋ฅผ ๋ฐํ์ผ๋ก ์ง์ ์คํ ๋ฆฌ ์์ฑ"""
|
| 861 |
-
prompt = f"""๋ค์ ์ฌ์ฉ์์ ์์ฒญ์ ๋ฐํ์ผ๋ก ์์ ํ ์คํ ๋ฆฌ ๊ธฐํ์์ ์์ฑํด์ฃผ์ธ์.
|
| 862 |
-
|
| 863 |
-
์ฌ์ฉ์ ์์ฒญ: "{user_prompt}"
|
| 864 |
-
|
| 865 |
-
๋ค์ ํ์์ผ๋ก ์์ฑํด์ฃผ์ธ์:
|
| 866 |
-
|
| 867 |
-
[์คํ ๋ฆฌ ๊ฐ์]
|
| 868 |
-
(์ฌ์ฉ์ ์์ฒญ์ ๋ฐ์ํ ์ ์ฒด ์คํ ๋ฆฌ ๊ฐ์)
|
| 869 |
-
|
| 870 |
-
[3๋จ๊ณ ๊ฐ๋ฑ๊ตฌ์กฐ]
|
| 871 |
-
โข ์ธ์ ๊ฐ๋ฑ: (์ฃผ์ธ๊ณต vs ์ ๋์/ํ๊ฒฝ)
|
| 872 |
-
โข ๋ด์ ๊ฐ๋ฑ: (์ฃผ์ธ๊ณต์ ๋ด๋ฉด์ ๋๋ ๋ง)
|
| 873 |
-
โข ๊ด๊ณ์ ๊ฐ๋ฑ: (์ฃผ์ธ๊ณต๊ณผ ์ฃผ๋ณ ์ธ๋ฌผ๋ค ๊ฐ์ ๊ฐ๋ฑ)
|
| 874 |
-
|
| 875 |
-
[์คํ ๋ฆฌ ์ํฌ - 3๋ง ๊ตฌ์กฐ]
|
| 876 |
-
์ 1๋ง (์ค์ ):
|
| 877 |
-
- ์คํ๋: (์ฒซ ์ฅ๋ฉด ๋ฌ์ฌ)
|
| 878 |
-
- ์ผ์์ ์ธ๊ณ: (์ฃผ์ธ๊ณต์ ํ๋ฒํ ์ผ์)
|
| 879 |
-
- ์ด๋ฐ ์ฌ๊ฑด: (๋ชจํ์ ์์)
|
| 880 |
-
- ๊ฑฐ๋ถ์ ๊ณ ๋ฏผ: (์ฃผ์ธ๊ณต์ ๋ง์ค์)
|
| 881 |
-
|
| 882 |
-
์ 2๋ง (๋๋ฆฝ):
|
| 883 |
-
- ์ฒซ ๋ฒ์งธ ๊ด๋ฌธ: (์ฒซ ๋์ )
|
| 884 |
-
- ๋๋ฃ์ ์ : (์กฐ๋ ฅ์์ ์ ๋์ ๋ฑ์ฅ)
|
| 885 |
-
- ์๋ จ์ ์ฐ์: (์ ์ ์ฌํ๋๋ ๊ฐ๋ฑ)
|
| 886 |
-
- ๊ฐ์ง ์น๋ฆฌ/ํจ๋ฐฐ: (๋ฐ์ ์ง์ )
|
| 887 |
-
- ์ ๋ง์ ์๊ฐ: (์ต์ ์ )
|
| 888 |
-
|
| 889 |
-
์ 3๋ง (ํด๊ฒฐ):
|
| 890 |
-
- ๊ฐ์ฑ๊ณผ ๊นจ๋ฌ์: (์ฃผ์ธ๊ณต์ ๋ณํ)
|
| 891 |
-
- ์ต์ข
๋๊ฒฐ: (ํด๋ผ์ด๋งฅ์ค)
|
| 892 |
-
- ์๋ก์ด ์ธ๊ณ: (๋ณํ๋ ์ผ์)
|
| 893 |
-
|
| 894 |
-
[์บ๋ฆญํฐ ์ํฌ]
|
| 895 |
-
์ฃผ์ธ๊ณต:
|
| 896 |
-
โข ์์์ : (์บ๋ฆญํฐ์ ์ด๊ธฐ ์ํ)
|
| 897 |
-
โข ์๋ง: (์ํ๋ ๊ฒ)
|
| 898 |
-
โข ์ฝ์ : (๊ทน๋ณตํด์ผ ํ ๋จ์ )
|
| 899 |
-
โข ์ฑ์ฅ: (์ด๋ป๊ฒ ๋ณํํ๋๊ฐ)
|
| 900 |
-
โข ์ต์ข
์ํ: (๋ณํ ํ ๋ชจ์ต)
|
| 901 |
-
|
| 902 |
-
[ํต์ฌ ํ
๋ง์ ๋ฉ์์ง]
|
| 903 |
-
โข ํ๋ฉด ํ
๋ง: (๊ฒ์ผ๋ก ๋๋ฌ๋๋ ์ฃผ์ )
|
| 904 |
-
โข ์ฌ์ธต ํ
๋ง: (๊น์ ์๋ฏธ์ ์ฃผ์ )
|
| 905 |
-
โข ์ฒ ํ์ ์ง๋ฌธ: (๊ด๊ฐ์๊ฒ ๋์ง๋ ์ง๋ฌธ)"""
|
| 906 |
-
|
| 907 |
-
result = self.call_llm_sync([{"role": "user", "content": prompt}], "planner")
|
| 908 |
-
return {"content": result}
|
| 909 |
-
|
| 910 |
-
# --- Step 2: Story structure generation ---
|
| 911 |
-
def generate_story_structure(self, logline: str, genre: str) -> StoryStructure:
|
| 912 |
-
"""Generate detailed 40-episode story structure"""
|
| 913 |
-
genre_info = GENRE_ELEMENTS.get(genre, {})
|
| 914 |
-
|
| 915 |
-
prompt = f"""์ ํ๋ ๋ก๊ทธ๋ผ์ธ์ ๊ธฐ๋ฐ์ผ๋ก {genre} ์ฅ๋ฅด์ 40ํ ์๊ฒฐ ์น์์ค ๊ตฌ์กฐ๋ฅผ ์์ฑํ์ธ์.
|
| 916 |
-
|
| 917 |
-
๋ก๊ทธ๋ผ์ธ: {logline}
|
| 918 |
-
์ฅ๋ฅด: {genre}
|
| 919 |
-
|
| 920 |
-
์ฅ๋ฅด ํน์ฑ:
|
| 921 |
-
- ํต์ฌ ์์: {', '.join(genre_info.get('key_elements', []))}
|
| 922 |
-
- ์ธ๊ธฐ ํธ๋กํ: {', '.join(genre_info.get('popular_tropes', []))}
|
| 923 |
-
- ํ์ ํฌํจ: {', '.join(genre_info.get('must_have', []))}
|
| 924 |
-
- ์ํผ์๋ ๊ตฌ์กฐ: {genre_info.get('episode_structure', '')}
|
| 925 |
-
|
| 926 |
-
๋ค์ ํ์์ผ๋ก ์์ฑํ์ธ์:
|
| 927 |
-
|
| 928 |
-
[์ ๋ชฉ]
|
| 929 |
-
๋งค๋ ฅ์ ์ด๊ณ ๊ธฐ์ต์ ๋จ๋ ์ ๋ชฉ
|
| 930 |
-
|
| 931 |
-
[์๋์์ค]
|
| 932 |
-
์ ์ฒด ์ค๊ฑฐ๋ฆฌ๋ฅผ 3-5๋ฌธ์ฅ์ผ๋ก ์์ฝ
|
| 933 |
-
|
| 934 |
-
[์ฃผ์ ๋ฑ์ฅ์ธ๋ฌผ]
|
| 935 |
-
1. ์ฃผ์ธ๊ณต: [์ด๋ฆ] - [๋์ด, ์ง์
/์ ๋ถ, ์ฑ๊ฒฉ, ๋ชฉํ]
|
| 936 |
-
2. ์ฃผ์์ธ๋ฌผ2: [์ด๋ฆ] - [๊ด๊ณ, ์ญํ , ํน์ง]
|
| 937 |
-
3. ์ฃผ์์ธ๋ฌผ3: [์ด๋ฆ] - [๊ด๊ณ, ์ญํ , ํน์ง]
|
| 938 |
-
(ํ์ํ ๋งํผ ์ถ๊ฐ)
|
| 939 |
-
|
| 940 |
-
[์ธ๊ณ๊ด ์ค์ ]
|
| 941 |
-
์ํ์ ๋ฐฐ๊ฒฝ์ด ๋๋ ์ธ๊ณ ์ค์ (์๋, ์ฅ์, ํน์ ์ค์ ๋ฑ)
|
| 942 |
-
|
| 943 |
-
[40ํ ์์ธ ๊ตฌ์ฑ]
|
| 944 |
-
๊ฐ ํ๋ง๋ค ๋ค์ ๋ด์ฉ ํฌํจ:
|
| 945 |
-
- ์ ๋ชฉ
|
| 946 |
-
- ์ฃผ์ ์ฌ๊ฑด
|
| 947 |
-
- ๊ฐ๋ฑ/์ ํ์
|
| 948 |
-
- ์๋ฉ ํ
|
| 949 |
-
|
| 950 |
-
1ํ: [์ ๋ชฉ]
|
| 951 |
-
- ์ฃผ์ ์ฌ๊ฑด:
|
| 952 |
-
- ๊ฐ๋ฑ/์ ํ์ :
|
| 953 |
-
- ์๋ฉ ํ
:
|
| 954 |
-
|
| 955 |
-
2ํ: [์ ๋ชฉ]
|
| 956 |
-
... (40ํ๊น์ง)
|
| 957 |
-
|
| 958 |
-
[์ฃผ์ ์ ํ์ ]
|
| 959 |
-
- 10ํ: 1์ฐจ ์ ํ์
|
| 960 |
-
- 20ํ: ์ค๊ฐ ํด๋ผ์ด๋งฅ์ค
|
| 961 |
-
- 30ํ: ์ต์ข
๊ฐ๋ฑ ์ง์
|
| 962 |
-
- 40ํ: ๋๋จ์
|
| 963 |
-
|
| 964 |
-
๋ชจ๋ ํ๋ 500๋จ์ด ๋ถ๋์ผ๋ก ์์ฑ๋ ์์ ์ด๋ฉฐ, ๊ฐ ํ๋ง๋ค ๋
์๋ฅผ ์ฌ๋ก์ก๋ ํ
์ด ํ์ํฉ๋๋ค."""
|
| 965 |
-
|
| 966 |
-
response = self.call_llm_sync([{"role": "user", "content": prompt}], "planner")
|
| 967 |
-
|
| 968 |
-
# Parse response into StoryStructure
|
| 969 |
-
story = StoryStructure()
|
| 970 |
-
story.genre = genre
|
| 971 |
-
|
| 972 |
-
# Parse the response and fill StoryStructure
|
| 973 |
-
lines = response.split('\n')
|
| 974 |
-
current_section = ""
|
| 975 |
-
episode_num = 0
|
| 976 |
-
|
| 977 |
-
for line in lines:
|
| 978 |
-
line = line.strip()
|
| 979 |
-
if '[์ ๋ชฉ]' in line:
|
| 980 |
-
current_section = 'title'
|
| 981 |
-
elif '[์๋์์ค]' in line:
|
| 982 |
-
current_section = 'synopsis'
|
| 983 |
-
elif '[์ฃผ์ ๋ฑ์ฅ์ธ๋ฌผ]' in line:
|
| 984 |
-
current_section = 'characters'
|
| 985 |
-
elif '[์ธ๊ณ๊ด ์ค์ ]' in line:
|
| 986 |
-
current_section = 'world'
|
| 987 |
-
elif '[40ํ ์์ธ ๊ตฌ์ฑ]' in line:
|
| 988 |
-
current_section = 'episodes'
|
| 989 |
-
elif line and current_section:
|
| 990 |
-
if current_section == 'title' and not story.title:
|
| 991 |
-
story.title = line
|
| 992 |
-
elif current_section == 'synopsis':
|
| 993 |
-
story.synopsis += line + " "
|
| 994 |
-
elif current_section == 'world':
|
| 995 |
-
story.world_setting += line + " "
|
| 996 |
-
elif current_section == 'episodes':
|
| 997 |
-
# Parse episode structure
|
| 998 |
-
if 'ํ:' in line:
|
| 999 |
-
# Extract episode number more robustly
|
| 1000 |
-
episode_part = line.split('ํ:')[0].strip()
|
| 1001 |
-
# Remove any asterisks or special characters
|
| 1002 |
-
episode_part = episode_part.replace('*', '').replace('#', '').strip()
|
| 1003 |
-
try:
|
| 1004 |
-
episode_num = int(episode_part)
|
| 1005 |
-
title = line.split('ํ:')[1].strip() if ':' in line else ""
|
| 1006 |
-
story.episode_outlines[episode_num] = {"title": title}
|
| 1007 |
-
except ValueError:
|
| 1008 |
-
# Try to extract number using regex
|
| 1009 |
-
import re
|
| 1010 |
-
numbers = re.findall(r'\d+', episode_part)
|
| 1011 |
-
if numbers:
|
| 1012 |
-
episode_num = int(numbers[0])
|
| 1013 |
-
title = line.split('ํ:')[1].strip() if ':' in line else ""
|
| 1014 |
-
story.episode_outlines[episode_num] = {"title": title}
|
| 1015 |
-
elif episode_num > 0:
|
| 1016 |
-
if '์ฃผ์ ์ฌ๊ฑด:' in line:
|
| 1017 |
-
story.episode_outlines[episode_num]["main_event"] = line.split(':', 1)[1].strip()
|
| 1018 |
-
elif '๊ฐ๋ฑ/์ ํ์ :' in line:
|
| 1019 |
-
story.episode_outlines[episode_num]["conflict"] = line.split(':', 1)[1].strip()
|
| 1020 |
-
elif '์๋ฉ ํ
:' in line:
|
| 1021 |
-
story.episode_outlines[episode_num]["hook"] = line.split(':', 1)[1].strip()
|
| 1022 |
-
elif episode_num in story.episode_outlines and '์ฃผ์ ์ฌ๊ฑด' not in line and '๊ฐ๋ฑ' not in line and '์๋ฉ' not in line:
|
| 1023 |
-
# Handle continuation lines
|
| 1024 |
-
if 'main_event' in story.episode_outlines[episode_num] and not story.episode_outlines[episode_num].get('conflict'):
|
| 1025 |
-
story.episode_outlines[episode_num]["main_event"] += " " + line
|
| 1026 |
-
elif 'conflict' in story.episode_outlines[episode_num] and not story.episode_outlines[episode_num].get('hook'):
|
| 1027 |
-
story.episode_outlines[episode_num]["conflict"] += " " + line
|
| 1028 |
-
elif 'hook' in story.episode_outlines[episode_num]:
|
| 1029 |
-
story.episode_outlines[episode_num]["hook"] += " " + line
|
| 1030 |
-
|
| 1031 |
-
return story
|
| 1032 |
-
|
| 1033 |
-
# --- Step 3: Episode writing ---
|
| 1034 |
-
def write_episode(self, story_structure: StoryStructure, episode_num: int,
|
| 1035 |
-
previous_episodes: List[str] = None) -> Dict[str, str]:
|
| 1036 |
-
"""Write a single episode based on story structure"""
|
| 1037 |
-
genre_info = GENRE_ELEMENTS.get(story_structure.genre, {})
|
| 1038 |
-
episode_outline = story_structure.episode_outlines.get(episode_num, {})
|
| 1039 |
-
hooks = EPISODE_HOOKS.get(story_structure.genre, ["๋ค์ ์๊ฐ, ์ถฉ๊ฒฉ์ ์ธ ์ผ์ด..."])
|
| 1040 |
-
|
| 1041 |
-
# Get previous context
|
| 1042 |
-
prev_context = ""
|
| 1043 |
-
if previous_episodes and len(previous_episodes) > 0:
|
| 1044 |
-
# Get last 2 episodes for context
|
| 1045 |
-
recent_episodes = previous_episodes[-2:]
|
| 1046 |
-
prev_context = "\n\n".join(recent_episodes)
|
| 1047 |
-
|
| 1048 |
-
prompt = f"""์น์์ค {story_structure.title}์ {episode_num}ํ๋ฅผ ์์ฑํ์ธ์.
|
| 1049 |
-
|
| 1050 |
-
์ฅ๋ฅด: {story_structure.genre}
|
| 1051 |
-
์ ์ฒด ์๋์์ค: {story_structure.synopsis}
|
| 1052 |
-
|
| 1053 |
-
{episode_num}ํ ๊ตฌ์ฑ:
|
| 1054 |
-
- ์ ๋ชฉ: {episode_outline.get('title', '')}
|
| 1055 |
-
- ์ฃผ์ ์ฌ๊ฑด: {episode_outline.get('main_event', '')}
|
| 1056 |
-
- ๊ฐ๋ฑ/์ ํ์ : {episode_outline.get('conflict', '')}
|
| 1057 |
-
- ์๋ฉ ํ
: {episode_outline.get('hook', '')}
|
| 1058 |
-
|
| 1059 |
-
์ด์ ๋ด์ฉ:
|
| 1060 |
-
{prev_context if prev_context else "์ฒซ ํ์
๋๋ค."}
|
| 1061 |
-
|
| 1062 |
-
์์ฑ ์๊ตฌ์ฌํญ:
|
| 1063 |
-
1. ๋ถ๋: 500๋จ์ด (์๊ฒฉํ ์ค์)
|
| 1064 |
-
2. ๋ฌธ์ฒด: {story_structure.genre} ์ฅ๋ฅด์ ๋ง๋ ๋ฌธ์ฒด
|
| 1065 |
-
3. ๊ตฌ์ฑ:
|
| 1066 |
-
- ๋์
๋ถ (์ด์ ํ ์ฐ๊ฒฐ)
|
| 1067 |
-
- ์ ๊ฐ๋ถ (์ฃผ์ ์ฌ๊ฑด ์งํ)
|
| 1068 |
-
- ํด๋ผ์ด๋งฅ์ค (๊ฐ๋ฑ/์ ํ์ )
|
| 1069 |
-
- ์๋ฉ (๊ฐ๋ ฅํ ํ
์ผ๋ก ๋ง๋ฌด๋ฆฌ)
|
| 1070 |
-
4. ํ์ ํฌํจ:
|
| 1071 |
-
- ์์ํ ๋ํ
|
| 1072 |
-
- ์บ๋ฆญํฐ ๊ฐ์ ๋ฌ์ฌ
|
| 1073 |
-
- ์ฅ๋ฉด ์ ํ
|
| 1074 |
-
- ๋
์ ๋ชฐ์
์์
|
| 1075 |
-
|
| 1076 |
-
์ฐธ๊ณ ํ
์์:
|
| 1077 |
-
{random.choice(hooks)}
|
| 1078 |
-
|
| 1079 |
-
ํ์:
|
| 1080 |
-
์ {episode_num}ํ. {episode_outline.get('title', '์ ๋ชฉ')}
|
| 1081 |
-
|
| 1082 |
-
(๋ณธ๋ฌธ ๋ด์ฉ)
|
| 1083 |
-
|
| 1084 |
-
๋ง์ง๋ง์ ๋ฐ๋์ ๋ค์ ํ๋ฅผ ๊ธฐ๋ํ๊ฒ ๋ง๋๋ ๊ฐ๋ ฅํ ํ
์ผ๋ก ๋๋ด์ธ์."""
|
| 1085 |
-
|
| 1086 |
-
response = self.call_llm_sync([{"role": "user", "content": prompt}], "writer")
|
| 1087 |
-
|
| 1088 |
-
# Extract title and content
|
| 1089 |
-
lines = response.strip().split('\n')
|
| 1090 |
-
title = lines[0] if lines else f"์ {episode_num}ํ"
|
| 1091 |
-
content = '\n'.join(lines[1:]) if len(lines) > 1 else response
|
| 1092 |
-
|
| 1093 |
-
# Extract hook (last sentence)
|
| 1094 |
-
sentences = content.split('.')
|
| 1095 |
-
hook = sentences[-2] + '.' if len(sentences) > 1 else sentences[-1]
|
| 1096 |
-
|
| 1097 |
-
return {
|
| 1098 |
-
"title": title,
|
| 1099 |
-
"content": content,
|
| 1100 |
-
"hook": hook,
|
| 1101 |
-
"word_count": len(content.split())
|
| 1102 |
-
}
|
| 1103 |
-
|
| 1104 |
-
# --- LLM call functions ---
|
| 1105 |
-
def call_llm_sync(self, messages: List[Dict[str, str]], role: str) -> str:
|
| 1106 |
-
logger.info(f"LLM ํธ์ถ ์์ - ์ญํ : {role}")
|
| 1107 |
-
logger.debug(f"๋ฉ์์ง ์: {len(messages)}")
|
| 1108 |
-
|
| 1109 |
-
try:
|
| 1110 |
-
system_prompts = self.get_system_prompts()
|
| 1111 |
-
full_messages = [{"role": "system", "content": system_prompts.get(role, "")}, *messages]
|
| 1112 |
-
|
| 1113 |
-
payload = {
|
| 1114 |
-
"model": self.model_id,
|
| 1115 |
-
"messages": full_messages,
|
| 1116 |
-
"max_tokens": 5000,
|
| 1117 |
-
"temperature": 0.85,
|
| 1118 |
-
"top_p": 0.95,
|
| 1119 |
-
"stream": False
|
| 1120 |
-
}
|
| 1121 |
-
|
| 1122 |
-
logger.debug(f"API ์์ฒญ ์ค... URL: {self.api_url}")
|
| 1123 |
-
start_time = time.time()
|
| 1124 |
-
|
| 1125 |
-
response = requests.post(
|
| 1126 |
-
self.api_url,
|
| 1127 |
-
headers=self.create_headers(),
|
| 1128 |
-
json=payload,
|
| 1129 |
-
timeout=180
|
| 1130 |
-
)
|
| 1131 |
-
|
| 1132 |
-
elapsed_time = time.time() - start_time
|
| 1133 |
-
logger.info(f"API ์๋ต ์์ - ์์์๊ฐ: {elapsed_time:.2f}์ด, ์ํ์ฝ๋: {response.status_code}")
|
| 1134 |
-
|
| 1135 |
-
if response.status_code != 200:
|
| 1136 |
-
logger.error(f"API ์ค๋ฅ: {response.status_code} - {response.text}")
|
| 1137 |
-
return f"โ API Error (Status Code: {response.status_code})"
|
| 1138 |
-
|
| 1139 |
-
result = response.json()
|
| 1140 |
-
if 'choices' in result and len(result['choices']) > 0:
|
| 1141 |
-
content = result['choices'][0]['message']['content'].strip()
|
| 1142 |
-
logger.info(f"LLM ์๋ต ๊ธธ์ด: {len(content)} ๋ฌธ์")
|
| 1143 |
-
return content
|
| 1144 |
-
else:
|
| 1145 |
-
logger.error(f"์์์น ๋ชปํ ์๋ต ํ์: {result}")
|
| 1146 |
-
return "โ No response from API"
|
| 1147 |
-
|
| 1148 |
-
except requests.exceptions.Timeout:
|
| 1149 |
-
logger.error("API ํธ์ถ ํ์์์")
|
| 1150 |
-
return "โ API ํธ์ถ ์๊ฐ ์ด๊ณผ"
|
| 1151 |
-
except Exception as e:
|
| 1152 |
-
logger.error(f"LLM ํธ์ถ ์ค๋ฅ: {type(e).__name__}: {str(e)}", exc_info=True)
|
| 1153 |
-
return f"โ Error: {str(e)}"
|
| 1154 |
-
|
| 1155 |
-
def get_system_prompts(self) -> Dict[str, str]:
|
| 1156 |
-
"""System prompts for different roles"""
|
| 1157 |
-
return {
|
| 1158 |
-
"planner": """๋น์ ์ ํ๊ตญ ์น์์ค ์์ฅ์ ์๋ฒฝํ ์ดํดํ๋ ๊ธฐํ์์
๋๋ค.
|
| 1159 |
-
๋
์๋ฅผ ์ค๋
์ํค๋ ํ๋กฏ๊ณผ ์ ๊ฐ๋ฅผ ์ค๊ณํฉ๋๋ค.
|
| 1160 |
-
์ฅ๋ฅด๋ณ ๊ด์ต๊ณผ ๋
์ ๊ธฐ๋๋ฅผ ์ ํํ ํ์
ํฉ๋๋ค.
|
| 1161 |
-
40ํ ์๊ฒฐ ๊ตฌ์กฐ๋ก ์๋ฒฝํ ๊ธฐ์น์ ๊ฒฐ์ ๋ง๋ญ๋๋ค.""",
|
| 1162 |
-
|
| 1163 |
-
"writer": """๋น์ ์ ๋
์๋ฅผ ์ฌ๋ก์ก๋ ์น์์ค ์๊ฐ์
๋๋ค.
|
| 1164 |
-
์์ํ๊ณ ๋ชฐ์
๊ฐ ์๋ ๋ฌธ์ฒด๋ฅผ ๊ตฌ์ฌํฉ๋๋ค.
|
| 1165 |
-
๊ฐ ํ๋ฅผ ์ ํํ 500๋จ์ด๋ก ์์ฑํฉ๋๋ค.
|
| 1166 |
-
๋ํ, ํ๋, ๋ด๋ฉด ๋ฌ์ฌ๋ฅผ ๊ท ํ์๊ฒ ๋ฐฐ์นํฉ๋๋ค.
|
| 1167 |
-
๋งค ํ ๋์ ๊ฐ๋ ฅํ ํํฌ๋ก ๋ค์ ํ๋ฅผ ๊ธฐ๋ค๋ฆฌ๊ฒ ๋ง๋ญ๋๋ค."""
|
| 1168 |
-
}
|
| 1169 |
-
|
| 1170 |
-
# --- Helper functions from paste.txt ---
|
| 1171 |
-
def determine_genre(categories_words: List[Tuple[str, str]]) -> str:
|
| 1172 |
-
"""์ ํ๋ ๋จ์ด๋ค์ ๊ธฐ๋ฐ์ผ๋ก ์ฅ๋ฅด๋ฅผ ๊ฒฐ์ """
|
| 1173 |
-
fantasy_words = {"๋ง๋ฒ์ฌ", "๊ธฐ์ฌ", "์ฉ์ฌ", "๋ง๋ฒ", "์ฃผ๋ฌธ์", "์ฑ", "๋์ ", "์ ์ฃผ", "์ถ๋ณต"}
|
| 1174 |
-
mystery_words = {"ํ์ ", "ํ์ฌ", "์ฆ๊ฑฐ", "๋ฒ์ฃํ์ฅ", "์ค์ข
", "์ด์ธ", "์ถ๋ฆฌ"}
|
| 1175 |
-
sf_words = {"์ฐ์ฃผ", "AI", "๋ก๋ด", "ํ๋ก๊ทธ๋จ", "ํ์๋จธ์ ", "์ฌ์ด๋ณด๊ทธ"}
|
| 1176 |
-
horror_words = {"์ ๋ น", "์
๋ง", "์ ์ฃผ", "๊ณตํฌ", "๋ฌ์ง", "ํผ"}
|
| 1177 |
-
romance_words = {"์ฌ๋", "์ฐ์ธ", "์ฒซ๋ง๋จ", "ํ๋กํฌ์ฆ", "๋ฐ์ดํธ"}
|
| 1178 |
-
|
| 1179 |
-
words = [word for _, word in categories_words]
|
| 1180 |
-
|
| 1181 |
-
if any(word in fantasy_words for word in words):
|
| 1182 |
-
return "ํํ์ง"
|
| 1183 |
-
elif any(word in mystery_words for word in words):
|
| 1184 |
-
return "๋ฏธ์คํฐ๋ฆฌ"
|
| 1185 |
-
elif any(word in sf_words for word in words):
|
| 1186 |
-
return "SF"
|
| 1187 |
-
elif any(word in horror_words for word in words):
|
| 1188 |
-
return "ํธ๋ฌ"
|
| 1189 |
-
elif any(word in romance_words for word in words):
|
| 1190 |
-
return "๋ก๋งจ์ค"
|
| 1191 |
-
else:
|
| 1192 |
-
return "ํ๋๊ทน"
|
| 1193 |
-
|
| 1194 |
-
def generate_comprehensive_story_plan(selected_logline: str, categories_words: List[Tuple[str, str]], genre: str) -> Dict[str, str]:
|
| 1195 |
-
"""์ ํ๋ ๋ก๊ทธ๋ผ์ธ์ ๊ธฐ๋ฐ์ผ๋ก ํฌ๊ด์ ์ธ ์คํ ๋ฆฌ ๊ธฐํ์ ์์ฑ"""
|
| 1196 |
-
system = WebNovelSystem()
|
| 1197 |
-
|
| 1198 |
-
prompt = f"""๋ค์ ๋ก๊ทธ๋ผ์ธ์ ๊ธฐ๋ฐ์ผ๋ก {genre} ์ฅ๋ฅด์ ์์ ํ ์คํ ๋ฆฌ ๊ธฐํ์์ ์์ฑํด์ฃผ์ธ์.
|
| 1199 |
-
|
| 1200 |
-
์ ํ๋ ๋ก๊ทธ๋ผ์ธ: {selected_logline}
|
| 1201 |
-
|
| 1202 |
-
์ฌ์ฉ๋ ๋จ์ด:
|
| 1203 |
-
1. {categories_words[0][0]}: {categories_words[0][1]}
|
| 1204 |
-
2. {categories_words[1][0]}: {categories_words[1][1]}
|
| 1205 |
-
3. {categories_words[2][0]}: {categories_words[2][1]}
|
| 1206 |
-
|
| 1207 |
-
๋ค์ ํ์์ผ๋ก ์์ฑํด์ฃผ์ธ์:
|
| 1208 |
-
|
| 1209 |
-
[3๋จ๊ณ ๊ฐ๋ฑ๊ตฌ์กฐ]
|
| 1210 |
-
โข ์ธ์ ๊ฐ๋ฑ: (์ฃผ์ธ๊ณต vs ์ ๋์/ํ๊ฒฝ)
|
| 1211 |
-
โข ๋ด์ ๊ฐ๋ฑ: (์ฃผ์ธ๊ณต์ ๋ด๋ฉด์ ๋๋ ๋ง)
|
| 1212 |
-
โข ๊ด๊ณ์ ๊ฐ๋ฑ: (์ฃผ์ธ๊ณต๊ณผ ์ฃผ๋ณ ์ธ๋ฌผ๋ค ๊ฐ์ ๊ฐ๋ฑ)
|
| 1213 |
-
|
| 1214 |
-
[์คํ ๋ฆฌ ์ํฌ - 3๋ง ๊ตฌ์กฐ]
|
| 1215 |
-
์ 1๋ง (์ค์ ):
|
| 1216 |
-
- ์คํ๋: (์ฒซ ์ฅ๋ฉด ๋ฌ์ฌ)
|
| 1217 |
-
- ์ผ์์ ์ธ๊ณ: (์ฃผ์ธ๊ณต์ ํ๋ฒํ ์ผ์)
|
| 1218 |
-
- ์ด๋ฐ ์ฌ๊ฑด: (๋ชจํ์ ์์)
|
| 1219 |
-
- ๊ฑฐ๋ถ์ ๊ณ ๋ฏผ: (์ฃผ์ธ๊ณต์ ๋ง์ค์)
|
| 1220 |
-
|
| 1221 |
-
์ 2๋ง (๋๋ฆฝ):
|
| 1222 |
-
- ์ฒซ ๋ฒ์งธ ๊ด๋ฌธ: (์ฒซ ๋์ )
|
| 1223 |
-
- ๋๋ฃ์ ์ : (์กฐ๋ ฅ์์ ์ ๋์ ๋ฑ์ฅ)
|
| 1224 |
-
- ์๋ จ์ ์ฐ์: (์ ์ ์ฌํ๋๋ ๊ฐ๋ฑ)
|
| 1225 |
-
- ๊ฐ์ง ์น๋ฆฌ/ํจ๋ฐฐ: (๋ฐ์ ์ง์ )
|
| 1226 |
-
- ์ ๋ง์ ์๊ฐ: (์ต์ ์ )
|
| 1227 |
-
|
| 1228 |
-
์ 3๋ง (ํด๊ฒฐ):
|
| 1229 |
-
- ๊ฐ์ฑ๊ณผ ๊นจ๋ฌ์: (์ฃผ์ธ๊ณต์ ๋ณํ)
|
| 1230 |
-
- ์ต์ข
๋๊ฒฐ: (ํด๋ผ์ด๋งฅ์ค)
|
| 1231 |
-
- ์๋ก์ด ์ธ๊ณ: (๋ณํ๋ ์ผ์)
|
| 1232 |
-
|
| 1233 |
-
[์บ๋ฆญํฐ ์ํฌ]
|
| 1234 |
-
์ฃผ์ธ๊ณต:
|
| 1235 |
-
โข ์์์ : (์บ๋ฆญํฐ์ ์ด๊ธฐ ์ํ)
|
| 1236 |
-
โข ์๋ง: (์ํ๋ ๊ฒ)
|
| 1237 |
-
โข ์ฝ์ : (๊ทน๋ณตํด์ผ ํ ๋จ์ )
|
| 1238 |
-
โข ์ฑ์ฅ: (์ด๋ป๊ฒ ๋ณํํ๋๊ฐ)
|
| 1239 |
-
โข ์ต์ข
์ํ: (๋ณํ ํ ๋ชจ์ต)
|
| 1240 |
-
|
| 1241 |
-
์ํ๊ณ ๋์คํธ:
|
| 1242 |
-
โข ์ ์ฒด: (๋๊ตฌ/๋ฌด์์ธ๊ฐ)
|
| 1243 |
-
โข ๋๊ธฐ: (์ ์ฃผ์ธ๊ณต๊ณผ ๋๋ฆฝํ๋๊ฐ)
|
| 1244 |
-
โข ๊ฐ์ : (๋ฌด์์ด ์ํ์ ์ธ๊ฐ)
|
| 1245 |
-
|
| 1246 |
-
[ํต์ฌ ํ
๋ง์ ๋ฉ์์ง]
|
| 1247 |
-
โข ํ๋ฉด ํ
๋ง: (๊ฒ์ผ๋ก ๋๋ฌ๋๋ ์ฃผ์ )
|
| 1248 |
-
โข ์ฌ์ธต ํ
๋ง: (๊น์ ์๋ฏธ์ ์ฃผ์ )
|
| 1249 |
-
โข ์ฒ ํ์ ์ง๋ฌธ: (๊ด๊ฐ์๊ฒ ๋์ง๋ ์ง๋ฌธ)
|
| 1250 |
-
|
| 1251 |
-
[3๊ฐ์ง ๋ฐ์ ํฌ์ธํธ]
|
| 1252 |
-
1. 1๋ง ํ๋ฐ: (์ฒซ ๋ฒ์งธ ๋๋ผ์)
|
| 1253 |
-
2. 2๋ง ์ค๋ฐ: (ํฐ ๋ฐ์ )
|
| 1254 |
-
3. 3๋ง ์ด๋ฐ: (์ต์ข
๋ฐ์ )
|
| 1255 |
-
|
| 1256 |
-
[๊ฐ๋ ํฌ์ธํธ]
|
| 1257 |
-
โข ํฌ์์ ์๊ฐ: (์ฃผ์ธ๊ณต์ด ํฌ๊ธฐํ๋ ๊ฒ)
|
| 1258 |
-
โข ํํด์ ์๊ฐ: (๊ด๊ณ ํ๋ณต)
|
| 1259 |
-
โข ์ฑ์ฅ์ ์๊ฐ: (์ง์ ํ ์์ ๋ฐ๊ฒฌ)"""
|
| 1260 |
-
|
| 1261 |
-
result = system.call_llm_sync([{"role": "user", "content": prompt}], "planner")
|
| 1262 |
-
return {"content": result}
|
| 1263 |
-
|
| 1264 |
-
def generate_loglines_step(user_prompt="", progress=gr.Progress()):
|
| 1265 |
-
"""Step 1: 10๊ฐ ๋ก๊ทธ๋ผ์ธ ์์ฑ ๋ฐ ํ๊ฐ"""
|
| 1266 |
-
global current_state
|
| 1267 |
-
|
| 1268 |
-
try:
|
| 1269 |
-
logger.info(f"=== ๋ก๊ทธ๋ผ์ธ ์์ฑ ์์ ===")
|
| 1270 |
-
logger.info(f"์ฌ์ฉ์ ์
๋ ฅ: {user_prompt[:100]}..." if user_prompt else "๋๋ค ์์ฑ ๋ชจ๋")
|
| 1271 |
-
|
| 1272 |
-
if user_prompt.strip():
|
| 1273 |
-
# ์ฌ์ฉ์ ํ๋กฌํํธ๊ฐ ์๋ ๊ฒฝ์ฐ
|
| 1274 |
-
progress(0.1, desc="๐ ์ฌ์ฉ์ ์์ฒญ ๋ถ์ ์ค...")
|
| 1275 |
-
logger.info("์ฌ์ฉ์ ํ๋กฌํํธ ๋ถ์ ์์")
|
| 1276 |
-
|
| 1277 |
-
current_state["user_prompt"] = user_prompt
|
| 1278 |
-
system = WebNovelSystem()
|
| 1279 |
-
|
| 1280 |
-
# ํ๋กฌํํธ ํด์
|
| 1281 |
-
interpreted = system.interpret_user_prompt(user_prompt)
|
| 1282 |
-
logger.info(f"ํ๋กฌํํธ ํด์ ์๋ฃ: {interpreted}")
|
| 1283 |
-
|
| 1284 |
-
# ๋จ์ด๊ฐ 3๊ฐ ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ ๋๋ค์ผ๋ก ์ฑ์ฐ๊ธฐ
|
| 1285 |
-
selected_words = interpreted["words"]
|
| 1286 |
-
while len(selected_words) < 3:
|
| 1287 |
-
remaining_categories = [cat for cat in complete_word_list.keys()
|
| 1288 |
-
if cat not in [w[0] for w in selected_words]]
|
| 1289 |
-
if remaining_categories:
|
| 1290 |
-
category = random.choice(remaining_categories)
|
| 1291 |
-
word = random.choice(complete_word_list[category])
|
| 1292 |
-
selected_words.append((category, word))
|
| 1293 |
-
logger.info(f"์ถ๊ฐ ๋จ์ด ์ ํ: {category} - {word}")
|
| 1294 |
-
|
| 1295 |
-
genre = interpreted["genre"] or determine_genre(selected_words)
|
| 1296 |
-
special_instructions = interpreted["special_instructions"]
|
| 1297 |
-
|
| 1298 |
-
# ์ํ ์ ์ฅ
|
| 1299 |
-
current_state["selected_words"] = selected_words
|
| 1300 |
-
current_state["genre"] = genre
|
| 1301 |
-
|
| 1302 |
-
# ์ ํ๋ ์นดํ
๊ณ ๋ฆฌ์ ๋จ์ด ํ์
|
| 1303 |
-
category_display = f"### ๐ฒ ๋ถ์ ๊ฒฐ๊ณผ\n\n**์ฌ์ฉ์ ์์ฒญ**: {user_prompt}\n\n**์ฅ๋ฅด**: {genre}\n\n**์ถ์ถ๋ ๋จ์ด**:\n" + "\n".join([f"โข {cat}: **{word}**" for cat, word in selected_words])
|
| 1304 |
-
if special_instructions:
|
| 1305 |
-
category_display += f"\n\n**ํน๋ณ ์ง์์ฌํญ**: {special_instructions}"
|
| 1306 |
-
|
| 1307 |
-
progress(0.3, desc="๐ ๋จ์ด ์ถ์ถ ์๋ฃ...")
|
| 1308 |
-
|
| 1309 |
-
# ํ๋กฌํํธ ๊ธฐ๋ฐ ๋ก๊ทธ๋ผ์ธ ์์ฑ
|
| 1310 |
-
progress(0.6, desc="๐ค 10๊ฐ์ ๋ก๊ทธ๋ผ์ธ์ ์์ฑํ๊ณ ํ๊ฐํ๋ ์ค...")
|
| 1311 |
-
logger.info("๋ก๊ทธ๋ผ์ธ ์์ฑ ์์")
|
| 1312 |
-
|
| 1313 |
-
logline_result = system.generate_10_loglines_with_prompt(user_prompt, selected_words, genre, special_instructions)
|
| 1314 |
-
logger.info(f"๋ก๊ทธ๋ผ์ธ ์์ฑ ์๋ฃ: {len(logline_result.get('loglines', []))}๊ฐ")
|
| 1315 |
-
|
| 1316 |
-
else:
|
| 1317 |
-
# ๋๋ค ์์ฑ
|
| 1318 |
-
progress(0.1, desc="๐ฒ ๋๋ค ๋จ์ด ์ ํ ์ค...")
|
| 1319 |
-
logger.info("๋๋ค ๋ชจ๋ ์์")
|
| 1320 |
-
|
| 1321 |
-
# 3๊ฐ์ ๋ค๋ฅธ ์นดํ
๊ณ ๋ฆฌ ๋๋ค ์ ํ
|
| 1322 |
-
selected_categories = random.sample(list(complete_word_list.keys()), 3)
|
| 1323 |
-
logger.info(f"์ ํ๋ ์นดํ
๊ณ ๋ฆฌ: {selected_categories}")
|
| 1324 |
-
|
| 1325 |
-
# ๊ฐ ์นดํ
๊ณ ๋ฆฌ์์ ๋๋ค ๋จ์ด ์ ํ
|
| 1326 |
-
selected_words = []
|
| 1327 |
-
for category in selected_categories:
|
| 1328 |
-
word = random.choice(complete_word_list[category])
|
| 1329 |
-
selected_words.append((category, word))
|
| 1330 |
-
logger.info(f"์ ํ๋ ๋จ์ด: {category} - {word}")
|
| 1331 |
-
|
| 1332 |
-
# ์ฅ๋ฅด ๊ฒฐ์
|
| 1333 |
-
genre = determine_genre(selected_words)
|
| 1334 |
-
logger.info(f"๊ฒฐ์ ๋ ์ฅ๋ฅด: {genre}")
|
| 1335 |
-
|
| 1336 |
-
# ์ํ ์ ์ฅ
|
| 1337 |
-
current_state["selected_words"] = selected_words
|
| 1338 |
-
current_state["genre"] = genre
|
| 1339 |
-
current_state["user_prompt"] = ""
|
| 1340 |
-
|
| 1341 |
-
# ์ ํ๋ ์นดํ
๊ณ ๋ฆฌ์ ๋จ์ด ํ์
|
| 1342 |
-
category_display = f"### ๐ฒ ์ ํ ๊ฒฐ๊ณผ\n\n**์ฅ๋ฅด**: {genre}\n\n**์ ํ๋ ๋จ์ด**:\n" + "\n".join([f"โข {cat}: **{word}**" for cat, word in selected_words])
|
| 1343 |
-
|
| 1344 |
-
progress(0.3, desc="๐ ๋จ์ด ์ ํ ์๋ฃ...")
|
| 1345 |
-
|
| 1346 |
-
# 10๊ฐ ๋ก๊ทธ๋ผ์ธ ์์ฑ ๋ฐ ํ๊ฐ
|
| 1347 |
-
progress(0.6, desc="๐ค 10๊ฐ์ ๋ก๊ทธ๋ผ์ธ์ ์์ฑํ๊ณ ํ๊ฐํ๋ ์ค...")
|
| 1348 |
-
logger.info("๋ก๊ทธ๋ผ์ธ ์์ฑ ์์")
|
| 1349 |
-
|
| 1350 |
-
system = WebNovelSystem()
|
| 1351 |
-
logline_result = system.generate_loglines_and_evaluate(selected_words)
|
| 1352 |
-
logger.info(f"๋ก๊ทธ๋ผ์ธ ์์ฑ ์๋ฃ: {len(logline_result.get('loglines', []))}๊ฐ")
|
| 1353 |
-
|
| 1354 |
-
# ํ๊ฐ ์ค ํ์
|
| 1355 |
-
progress(0.8, desc="โญ ๋ก๊ทธ๋ผ์ธ ํ๊ฐ ์ค...")
|
| 1356 |
-
|
| 1357 |
-
# ์ํ ์ ์ฅ
|
| 1358 |
-
current_state["loglines"] = logline_result.get('loglines', [])
|
| 1359 |
-
current_state["evaluations"] = logline_result.get('evaluations', [])
|
| 1360 |
-
current_state["ai_selected"] = logline_result.get('selected', '')
|
| 1361 |
-
current_state["ai_reason"] = logline_result.get('reason', '')
|
| 1362 |
-
|
| 1363 |
-
# ๋ก๊ทธ๋ผ์ธ ์ ๋ฆฌ
|
| 1364 |
-
loglines_display = "### ๐ ์์ฑ๋ 10๊ฐ ๋ก๊ทธ๋ผ์ธ\n\n"
|
| 1365 |
-
for i, logline in enumerate(logline_result.get('loglines', [])):
|
| 1366 |
-
loglines_display += f"**๋ก๊ทธ๋ผ์ธ {i+1}**: {logline}\n\n"
|
| 1367 |
-
|
| 1368 |
-
# AI ์ถ์ฒ ํ์
|
| 1369 |
-
if logline_result.get('selected'):
|
| 1370 |
-
loglines_display += f"### ๐ค AI ์ถ์ฒ\n\n**{logline_result['selected']}**\n\n"
|
| 1371 |
-
if logline_result.get('reason'):
|
| 1372 |
-
loglines_display += f"**์ถ์ฒ ์ด์ **: {logline_result['reason']}"
|
| 1373 |
-
|
| 1374 |
-
# ๋๋กญ๋ค์ด ์ ํ์ง ์์ฑ
|
| 1375 |
-
choices = [f"๋ก๊ทธ๋ผ์ธ {i+1}: {logline[:50]}..." for i, logline in enumerate(logline_result.get('loglines', []))]
|
| 1376 |
-
|
| 1377 |
-
progress(1.0, desc="โ
์๋ฃ!")
|
| 1378 |
-
logger.info("๋ก๊ทธ๋ผ์ธ ์์ฑ ํ๋ก์ธ์ค ์๋ฃ")
|
| 1379 |
-
|
| 1380 |
-
return (
|
| 1381 |
-
category_display,
|
| 1382 |
-
loglines_display,
|
| 1383 |
-
gr.update(visible=True, choices=choices, value=choices[0] if choices else None),
|
| 1384 |
-
gr.update(visible=True),
|
| 1385 |
-
gr.update(visible=True)
|
| 1386 |
-
)
|
| 1387 |
-
|
| 1388 |
-
except Exception as e:
|
| 1389 |
-
logger.error(f"๋ก๊ทธ๋ผ์ธ ์์ฑ ์ค๋ฅ: {str(e)}", exc_info=True)
|
| 1390 |
-
error_msg = f"### โ ์ค๋ฅ ๋ฐ์\n\n{str(e)}\n\n์์ธ ๋ก๊ทธ๋ฅผ ํ์ธํด์ฃผ์ธ์."
|
| 1391 |
-
return (
|
| 1392 |
-
error_msg,
|
| 1393 |
-
"",
|
| 1394 |
-
gr.update(visible=False, choices=[]),
|
| 1395 |
-
gr.update(visible=False),
|
| 1396 |
-
gr.update(visible=False)
|
| 1397 |
-
)
|
| 1398 |
-
|
| 1399 |
-
def generate_story_from_selection(selected_logline_dropdown):
|
| 1400 |
-
"""Step 2: ์ ํ๋ ๋ก๊ทธ๋ผ์ธ์ผ๋ก ์คํ ๋ฆฌ ์์ฑ"""
|
| 1401 |
-
global current_state
|
| 1402 |
-
|
| 1403 |
-
logger.info(f"=== ์คํ ๋ฆฌ ์์ฑ ์์ ===")
|
| 1404 |
-
logger.info(f"์ ํ๋ ๋ก๊ทธ๋ผ์ธ: {selected_logline_dropdown}")
|
| 1405 |
-
|
| 1406 |
-
if not selected_logline_dropdown:
|
| 1407 |
-
return "### โ ๏ธ ๋ก๊ทธ๋ผ์ธ์ ์ ํํด์ฃผ์ธ์", "", "", ""
|
| 1408 |
-
|
| 1409 |
-
try:
|
| 1410 |
-
# ์ ํ๋ ๋ก๊ทธ๋ผ์ธ ๋ฒํธ ์ถ์ถ
|
| 1411 |
-
logline_num = int(selected_logline_dropdown.split(':')[0].split()[-1]) - 1
|
| 1412 |
-
selected_logline = current_state["loglines"][logline_num]
|
| 1413 |
-
logger.info(f"๋ก๊ทธ๋ผ์ธ ๋ฒํธ {logline_num + 1} ์ ํ๋จ")
|
| 1414 |
-
|
| 1415 |
-
# ์งํ ์ํฉ ํ์
|
| 1416 |
-
progress_display = f"### โณ ์คํ ๋ฆฌ ๊ตฌ์ฑ ์ค...\n\n**์ ํ๋ ๋ก๊ทธ๋ผ์ธ**: {selected_logline}\n\n**์งํ ์ค**: AI๊ฐ ์คํ ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ์์ฑํ๊ณ ์์ต๋๋ค..."
|
| 1417 |
-
|
| 1418 |
-
# ์คํ ๋ฆฌ ๊ธฐํ์ ์์ฑ
|
| 1419 |
-
logger.info("์คํ ๋ฆฌ ๊ธฐํ์ ์์ฑ ์์")
|
| 1420 |
-
story_plan = generate_comprehensive_story_plan(
|
| 1421 |
-
selected_logline,
|
| 1422 |
-
current_state["selected_words"],
|
| 1423 |
-
current_state["genre"]
|
| 1424 |
-
)
|
| 1425 |
-
|
| 1426 |
-
if "error" in story_plan:
|
| 1427 |
-
logger.error(f"์คํ ๋ฆฌ ์์ฑ ์ค๋ฅ: {story_plan['error']}")
|
| 1428 |
-
return f"### โ ์ค๋ฅ\n\n{story_plan['error']}", "", "", ""
|
| 1429 |
-
|
| 1430 |
-
# ๊ธฐํ์ ๋ด์ฉ ํ์ฑ ๋ฐ ์ ๋ฆฌ
|
| 1431 |
-
full_plan = story_plan.get('content', '')
|
| 1432 |
-
logger.info(f"์คํ ๋ฆฌ ๊ธฐํ์ ์์ฑ ์๋ฃ - ๊ธธ์ด: {len(full_plan)} ๋ฌธ์")
|
| 1433 |
-
|
| 1434 |
-
# ์ ํ๋ ๋ก๊ทธ๋ผ์ธ ํ์
|
| 1435 |
-
selected_display = f"### ๐ฌ ์ ํ๋ ๋ก๊ทธ๋ผ์ธ\n\n**๋ก๊ทธ๋ผ์ธ {logline_num + 1}**: {selected_logline}"
|
| 1436 |
-
|
| 1437 |
-
# ์น์
๋ณ๋ก ๋ถ๋ฆฌ
|
| 1438 |
-
sections = {
|
| 1439 |
-
"๊ฐ๋ฑ๊ตฌ์กฐ": "",
|
| 1440 |
-
"์คํ ๋ฆฌ์ํฌ": "",
|
| 1441 |
-
"์บ๋ฆญํฐ์ํ
๋ง": ""
|
| 1442 |
-
}
|
| 1443 |
-
|
| 1444 |
-
# ๊ฐ๋จํ ๋ถ๋ฆฌ ๋ก์ง
|
| 1445 |
-
if "[3๋จ๊ณ ๊ฐ๋ฑ๊ตฌ์กฐ]" in full_plan:
|
| 1446 |
-
parts = full_plan.split("[์คํ ๋ฆฌ ์ํฌ")
|
| 1447 |
-
sections["๊ฐ๋ฑ๊ตฌ์กฐ"] = parts[0]
|
| 1448 |
-
|
| 1449 |
-
if len(parts) > 1:
|
| 1450 |
-
parts2 = parts[1].split("[์บ๋ฆญํฐ ์ํฌ]")
|
| 1451 |
-
sections["์คํ ๋ฆฌ์ํฌ"] = "[์คํ ๋ฆฌ ์ํฌ" + parts2[0]
|
| 1452 |
-
|
| 1453 |
-
if len(parts2) > 1:
|
| 1454 |
-
sections["์บ๋ฆญํฐ์ํ
๋ง"] = "[์บ๋ฆญํฐ ์ํฌ]\n" + parts2[1]
|
| 1455 |
-
|
| 1456 |
-
logger.info("์คํ ๋ฆฌ ์์ฑ ํ๋ก์ธ์ค ์๋ฃ")
|
| 1457 |
-
return selected_display, sections["๊ฐ๋ฑ๊ตฌ์กฐ"], sections["์คํ ๋ฆฌ์ํฌ"], sections["์บ๋ฆญํฐ์ํ
๋ง"]
|
| 1458 |
-
|
| 1459 |
-
except Exception as e:
|
| 1460 |
-
logger.error(f"์คํ ๋ฆฌ ์์ฑ ์ค๋ฅ: {str(e)}", exc_info=True)
|
| 1461 |
-
return f"### โ ์ค๋ฅ ๋ฐ์\n\n{str(e)}", "", "", ""
|
| 1462 |
-
|
| 1463 |
-
def generate_direct_story(user_prompt="", progress=gr.Progress()):
|
| 1464 |
-
"""์ฌ์ฉ์ ํ๋กฌํํธ๋ก ์ง์ ์คํ ๋ฆฌ ์์ฑ"""
|
| 1465 |
-
global current_state
|
| 1466 |
-
|
| 1467 |
-
if not user_prompt.strip():
|
| 1468 |
-
return "### โ ๏ธ ์ค๋ฅ\n\n์คํ ๋ฆฌ ์์ฑ์ ์ํ ์์ฒญ์ฌํญ์ ์
๋ ฅํด์ฃผ์ธ์.", "", "", ""
|
| 1469 |
-
|
| 1470 |
-
try:
|
| 1471 |
-
progress(0.5, desc="์ฌ์ฉ์ ์์ฒญ์ ๋ถ์ํ์ฌ ์คํ ๋ฆฌ๋ฅผ ์์ฑํ๋ ์ค... (30์ด ์์)")
|
| 1472 |
-
|
| 1473 |
-
system = WebNovelSystem()
|
| 1474 |
-
|
| 1475 |
-
# ์คํ ๋ฆฌ ์ง์ ์์ฑ
|
| 1476 |
-
story_result = system.generate_story_from_prompt(user_prompt)
|
| 1477 |
-
|
| 1478 |
-
# ๊ธฐํ์ ๋ด์ฉ ํ์ฑ ๋ฐ ์ ๋ฆฌ
|
| 1479 |
-
full_plan = story_result.get('content', '')
|
| 1480 |
-
|
| 1481 |
-
# ์์ฒญ์ฌํญ ๏ฟฝ๏ฟฝ๏ฟฝ์
|
| 1482 |
-
request_display = f"### ๐ ์ฌ์ฉ์ ์์ฒญ\n\n**์
๋ ฅ๋ ์์ฒญ**: {user_prompt}"
|
| 1483 |
-
|
| 1484 |
-
# ์น์
๋ณ๋ก ๋ถ๋ฆฌ
|
| 1485 |
-
sections = {
|
| 1486 |
-
"๊ฐ๋ฑ๊ตฌ์กฐ": "",
|
| 1487 |
-
"์คํ ๋ฆฌ์ํฌ": "",
|
| 1488 |
-
"์บ๋ฆญํฐ์ํ
๋ง": ""
|
| 1489 |
-
}
|
| 1490 |
-
|
| 1491 |
-
# ์น์
๋ถ๋ฆฌ
|
| 1492 |
-
if "[์คํ ๋ฆฌ ๊ฐ์]" in full_plan:
|
| 1493 |
-
parts = full_plan.split("[3๋จ๊ณ ๊ฐ๋ฑ๊ตฌ์กฐ]")
|
| 1494 |
-
overview = parts[0]
|
| 1495 |
-
|
| 1496 |
-
if len(parts) > 1:
|
| 1497 |
-
parts2 = parts[1].split("[์คํ ๋ฆฌ ์ํฌ")
|
| 1498 |
-
sections["๊ฐ๋ฑ๊ตฌ์กฐ"] = "[3๋จ๊ณ ๊ฐ๋ฑ๊ตฌ์กฐ]\n" + parts2[0]
|
| 1499 |
-
|
| 1500 |
-
if len(parts2) > 1:
|
| 1501 |
-
parts3 = parts2[1].split("[์บ๋ฆญํฐ ์ํฌ]")
|
| 1502 |
-
sections["์คํ ๋ฆฌ์ํฌ"] = "[์คํ ๋ฆฌ ์ํฌ" + parts3[0]
|
| 1503 |
-
|
| 1504 |
-
if len(parts3) > 1:
|
| 1505 |
-
sections["์บ๋ฆญํฐ์ํ
๋ง"] = "[์บ๋ฆญํฐ ์ํฌ]\n" + parts3[1]
|
| 1506 |
-
|
| 1507 |
-
progress(1.0, desc="์๋ฃ!")
|
| 1508 |
-
|
| 1509 |
-
return request_display + "\n\n" + overview, sections["๊ฐ๋ฑ๊ตฌ์กฐ"], sections["์คํ ๋ฆฌ์ํฌ"], sections["์บ๋ฆญํฐ์ํ
๋ง"]
|
| 1510 |
-
|
| 1511 |
-
except Exception as e:
|
| 1512 |
-
return f"### โ ๏ธ ์ค๋ฅ\n\n์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", "", ""
|
| 1513 |
-
|
| 1514 |
-
# --- Gradio interface ---
|
| 1515 |
-
def create_interface():
|
| 1516 |
-
with gr.Blocks(theme=gr.themes.Soft(), title="K-Story AI Studio") as interface:
|
| 1517 |
-
# Header with OAuth login status
|
| 1518 |
-
with gr.Row():
|
| 1519 |
-
gr.HTML("""
|
| 1520 |
-
<div style="text-align: center; margin-bottom: 2rem;">
|
| 1521 |
-
<h1 style="font-size: 3rem;">๐ K-Story AI Studio</h1>
|
| 1522 |
-
<p style="font-size: 1.2rem;">AI ๊ธฐ๋ฐ ํ๊ตญํ ์น์์ค ์ฐฝ์ ์์คํ
</p>
|
| 1523 |
-
</div>
|
| 1524 |
-
""")
|
| 1525 |
-
|
| 1526 |
-
with gr.Row():
|
| 1527 |
-
login_status = gr.Markdown("๐ ๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค")
|
| 1528 |
-
gr.LoginButton()
|
| 1529 |
-
|
| 1530 |
-
# State management
|
| 1531 |
-
user_state = gr.State(None)
|
| 1532 |
-
current_session = gr.State(None)
|
| 1533 |
-
story_structure_state = gr.State(None)
|
| 1534 |
-
|
| 1535 |
-
with gr.Tab("๐ ์ ์ํ ์์"):
|
| 1536 |
-
with gr.Column():
|
| 1537 |
-
# Step 1 UI (from paste.txt)
|
| 1538 |
-
gr.Markdown("""
|
| 1539 |
-
# ๐ฌ AI ์คํ ๋ฆฌ ๊ธฐํ ์์คํ
3.0
|
| 1540 |
-
|
| 1541 |
-
### ์ฌ์ฉ์์ ์์ฒญ์ ๋ฐ์ํ์ฌ ๋ง์ถคํ ์คํ ๋ฆฌ๋ฅผ ๊ฐ๋ฐํฉ๋๋ค!
|
| 1542 |
-
|
| 1543 |
-
#### ๐ ์ฃผ์ ๊ธฐ๋ฅ
|
| 1544 |
-
1. **์์ ๋ก์ด ์
๋ ฅ**: ์ํ๋ ์คํ ๋ฆฌ์ ๋ถ์๊ธฐ, ์ฅ๋ฅด, ํค์๋ ๋ฑ์ ์์ ๋กญ๊ฒ ์
๋ ฅ
|
| 1545 |
-
2. **10๊ฐ ๋ก๊ทธ๋ผ์ธ ์์ฑ**: ์
๋ ฅ๋ ์์ฒญ์ ๋ฐ์ํ ๋ค์ํ ๋ก๊ทธ๋ผ์ธ ์ ์
|
| 1546 |
-
3. **์ง์ ์คํ ๋ฆฌ ์์ฑ**: ๋ก๊ทธ๋ผ์ธ ๋จ๊ณ๋ฅผ ๊ฑด๋๋ฐ๊ณ ๋ฐ๋ก ์คํ ๋ฆฌ ์์ฑ ๊ฐ๋ฅ
|
| 1547 |
-
4. **AI ํ๊ฐ ์์คํ
**: ๋
์ฐฝ์ฑ, ํฅ๋ฏธ๋, ์์ฌ์ฑ, ๊ฐ์ฐ์ฑ ๊ธฐ์ค์ผ๋ก ํ๊ฐ
|
| 1548 |
-
""")
|
| 1549 |
-
|
| 1550 |
-
with gr.Row():
|
| 1551 |
-
with gr.Column(scale=3):
|
| 1552 |
-
user_prompt_input = gr.Textbox(
|
| 1553 |
-
label="๐๏ธ ์ํ๋ ์คํ ๋ฆฌ ์์ฒญ์ฌํญ์ ์
๋ ฅํ์ธ์ (์ ํ์ฌํญ)",
|
| 1554 |
-
placeholder="์์: '์ฐ์ฃผ๋ฅผ ๋ฐฐ๊ฒฝ์ผ๋ก ํ ๊ฐ๋์ ์ธ ๊ฐ์กฑ ์ด์ผ๊ธฐ', 'ํ์ ์ด ๋ฑ์ฅํ๋ ์ฝ๋ฏธ๋ ๋ฏธ์คํฐ๋ฆฌ', '์๊ฐ์ฌํ๊ณผ ์ฒซ์ฌ๋์ด ๊ฒฐํฉ๋ SF ๋ก๋งจ์ค'",
|
| 1555 |
-
lines=2
|
| 1556 |
-
)
|
| 1557 |
-
|
| 1558 |
-
with gr.Row():
|
| 1559 |
-
with gr.Column(scale=1):
|
| 1560 |
-
random_btn = gr.Button("๐ฒ ๋๋ค ๋ก๊ทธ๋ผ์ธ ์์ฑํ๊ธฐ", variant="primary", size="lg")
|
| 1561 |
-
with gr.Column(scale=1):
|
| 1562 |
-
generate_btn = gr.Button("โ๏ธ ์์ฒญ์ฌํญ ๋ฐ์ ๋ก๊ทธ๋ผ์ธ ์์ฑํ๊ธฐ", variant="primary", size="lg")
|
| 1563 |
-
with gr.Column(scale=1):
|
| 1564 |
-
direct_story_btn = gr.Button("๐ ๋ฐ๋ก ์คํ ๋ฆฌ ์์ฑํ๊ธฐ", variant="secondary", size="lg")
|
| 1565 |
-
|
| 1566 |
-
gr.Markdown("---")
|
| 1567 |
-
|
| 1568 |
-
with gr.Row():
|
| 1569 |
-
with gr.Column(scale=1):
|
| 1570 |
-
category_output = gr.Markdown(value="", label="์ ํ๋ ๋จ์ด")
|
| 1571 |
-
|
| 1572 |
-
with gr.Row():
|
| 1573 |
-
with gr.Column(scale=1):
|
| 1574 |
-
loglines_output = gr.Markdown(value="", label="๋ก๊ทธ๋ผ์ธ ์์ฑ ๋ฐ ํ๊ฐ")
|
| 1575 |
-
|
| 1576 |
-
with gr.Row():
|
| 1577 |
-
with gr.Column(scale=1):
|
| 1578 |
-
logline_dropdown = gr.Dropdown(
|
| 1579 |
-
label="๐ ์ํ๋ ๋ก๊ทธ๋ผ์ธ์ ์ ํํ์ธ์",
|
| 1580 |
-
choices=[],
|
| 1581 |
-
visible=False,
|
| 1582 |
-
interactive=True
|
| 1583 |
-
)
|
| 1584 |
-
generate_story_btn = gr.Button(
|
| 1585 |
-
"๐ฌ ์ ํํ ๋ก๊ทธ๋ผ์ธ์ผ๋ก ์คํ ๋ฆฌ ์์ฑํ๊ธฐ",
|
| 1586 |
-
variant="secondary",
|
| 1587 |
-
visible=False
|
| 1588 |
-
)
|
| 1589 |
-
|
| 1590 |
-
with gr.Row():
|
| 1591 |
-
with gr.Column(scale=1):
|
| 1592 |
-
story_header = gr.Markdown("### ๐ ์์ฑ๋ ์คํ ๋ฆฌ ๊ธฐํ์", visible=False)
|
| 1593 |
-
|
| 1594 |
-
with gr.Row():
|
| 1595 |
-
with gr.Column(scale=1):
|
| 1596 |
-
selected_logline_output = gr.Markdown(value="", label="์ ํ๋ ๋ก๊ทธ๋ผ์ธ")
|
| 1597 |
-
|
| 1598 |
-
with gr.Row():
|
| 1599 |
-
with gr.Column(scale=1):
|
| 1600 |
-
conflicts_output = gr.Markdown(value="", label="๊ฐ๋ฑ๊ตฌ์กฐ")
|
| 1601 |
-
|
| 1602 |
-
with gr.Row():
|
| 1603 |
-
with gr.Column(scale=1):
|
| 1604 |
-
story_arc_output = gr.Markdown(value="", label="์คํ ๋ฆฌ ์ํฌ")
|
| 1605 |
-
|
| 1606 |
-
with gr.Row():
|
| 1607 |
-
with gr.Column(scale=1):
|
| 1608 |
-
final_details_output = gr.Markdown(value="", label="์บ๋ฆญํฐ, ํ
๋ง, ๋ฐ์ ")
|
| 1609 |
-
|
| 1610 |
-
# Step 2-3: Web novel writing
|
| 1611 |
-
gr.Markdown("---")
|
| 1612 |
-
gr.Markdown("### ๐ ์น์์ค ์์ฑ")
|
| 1613 |
-
|
| 1614 |
-
genre_select = gr.Radio(
|
| 1615 |
-
choices=list(WEBNOVEL_GENRES.keys()),
|
| 1616 |
-
label="์ฅ๋ฅด ์ ํ",
|
| 1617 |
-
value="๋ก๋งจ์ค",
|
| 1618 |
-
visible=False
|
| 1619 |
-
)
|
| 1620 |
-
|
| 1621 |
-
generate_webnovel_btn = gr.Button("๐ ์น์์ค ๊ตฌ์ฑ ์์ฑ", variant="primary", visible=False)
|
| 1622 |
-
webnovel_structure_output = gr.Markdown(visible=False)
|
| 1623 |
-
|
| 1624 |
-
write_first_btn = gr.Button("โ๏ธ 1ํ ์์ฑ", variant="primary", visible=False)
|
| 1625 |
-
episode_output = gr.Markdown(visible=False)
|
| 1626 |
-
write_next_btn = gr.Button("โก๏ธ ๋ค์ํ ์์ฑ", variant="secondary", visible=False)
|
| 1627 |
-
episode_counter = gr.State(1)
|
| 1628 |
-
|
| 1629 |
-
with gr.Tab("๐ ๋ด ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ"):
|
| 1630 |
-
refresh_library_btn = gr.Button("๐ ์๋ก๊ณ ์นจ")
|
| 1631 |
-
library_output = gr.HTML()
|
| 1632 |
-
|
| 1633 |
-
with gr.Row():
|
| 1634 |
-
selected_novel = gr.Dropdown(label="์ํ ์ ํ", visible=False)
|
| 1635 |
-
continue_writing_btn = gr.Button("์ด์ด์ฐ๊ธฐ", visible=False)
|
| 1636 |
-
preview_btn = gr.Button("๋ฏธ๋ฆฌ๋ณด๊ธฐ", visible=False)
|
| 1637 |
-
|
| 1638 |
-
# Event handlers
|
| 1639 |
-
|
| 1640 |
-
def check_login(request: gr.Request):
|
| 1641 |
-
"""Check if user is logged in via OAuth"""
|
| 1642 |
-
logger.info("=== ๋ก๊ทธ์ธ ์ฒดํฌ ===")
|
| 1643 |
-
|
| 1644 |
-
# OAuth ์ ์ ํ์ธ
|
| 1645 |
-
user_info = None
|
| 1646 |
-
if request:
|
| 1647 |
-
user_info = request.username
|
| 1648 |
-
logger.info(f"OAuth username: {user_info}")
|
| 1649 |
-
|
| 1650 |
-
# Hugging Face Spaces์ ๊ฒฝ์ฐ ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ํ์ธ
|
| 1651 |
-
if not user_info and hasattr(request, 'headers'):
|
| 1652 |
-
# ํค๋์์ ์ ์ ์ ๋ณด ์ถ์ถ ์๋
|
| 1653 |
-
auth_header = request.headers.get('x-user-info', '')
|
| 1654 |
-
if auth_header:
|
| 1655 |
-
user_info = auth_header
|
| 1656 |
-
logger.info(f"Header user info: {user_info}")
|
| 1657 |
-
|
| 1658 |
-
if user_info:
|
| 1659 |
-
# OAuth ๋ก๊ทธ์ธ ์ฑ๊ณต
|
| 1660 |
-
WebNovelDatabase.create_or_update_user(
|
| 1661 |
-
user_id=user_info,
|
| 1662 |
-
username=user_info
|
| 1663 |
-
)
|
| 1664 |
-
return f"๐ค {user_info}๋ ํ์ํฉ๋๋ค!", {"user_id": user_info, "username": user_info}
|
| 1665 |
-
else:
|
| 1666 |
-
# ๊ฐ๋ฐ/๋ฐ๋ชจ ๋ชจ๋ - ๊ณ ์ ์ธ์
ID ์์ฑ
|
| 1667 |
-
session_id = hashlib.md5(f"guest_{datetime.now()}_{random.randint(1000,9999)}".encode()).hexdigest()[:8]
|
| 1668 |
-
guest_user = f"guest_{session_id}"
|
| 1669 |
-
|
| 1670 |
-
WebNovelDatabase.create_or_update_user(
|
| 1671 |
-
user_id=guest_user,
|
| 1672 |
-
username=f"๊ฒ์คํธ_{session_id}"
|
| 1673 |
-
)
|
| 1674 |
-
|
| 1675 |
-
logger.info(f"๊ฒ์คํธ ์ ์ ์์ฑ: {guest_user}")
|
| 1676 |
-
return f"๐ญ ๊ฒ์คํธ ๋ชจ๋ (ID: {session_id})", {"user_id": guest_user, "username": f"๊ฒ์คํธ_{session_id}"}
|
| 1677 |
-
|
| 1678 |
-
|
| 1679 |
-
def show_genre_after_story(story_output, user_state):
|
| 1680 |
-
"""์คํ ๋ฆฌ ์์ฑ ํ ์ฅ๋ฅด ์ ํ ํ์ - user_state ์ ์ง"""
|
| 1681 |
-
logger.info(f"์คํ ๋ฆฌ ์์ฑ ์๋ฃ ์ฒดํฌ: {bool(story_output and '###' in story_output)}")
|
| 1682 |
-
logger.info(f"user_state ์ ์ง: {user_state}")
|
| 1683 |
-
if story_output and "###" in story_output:
|
| 1684 |
-
return gr.update(visible=True), gr.update(visible=True), user_state
|
| 1685 |
-
return gr.update(visible=False), gr.update(visible=False), user_state
|
| 1686 |
-
|
| 1687 |
-
|
| 1688 |
-
def generate_webnovel_structure(selected_logline_dropdown, genre, request: gr.Request):
|
| 1689 |
-
"""Generate web novel structure from logline and genre"""
|
| 1690 |
-
logger.info(f"=== ์น์์ค ๊ตฌ์กฐ ์์ฑ ์์ ===")
|
| 1691 |
-
logger.info(f"์ฅ๋ฅด: {genre}")
|
| 1692 |
-
|
| 1693 |
-
# ์ ์ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ (OAuth ๋๋ ๊ฒ์คํธ)
|
| 1694 |
-
user_state = get_user_state(request)
|
| 1695 |
-
|
| 1696 |
-
if not user_state:
|
| 1697 |
-
logger.error("์ ์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์")
|
| 1698 |
-
return gr.update(value="### โ ๏ธ ์ค๋ฅ\n\nํ์ด์ง๋ฅผ ์๋ก๊ณ ์นจํด์ฃผ์ธ์."), gr.update(), None
|
| 1699 |
-
|
| 1700 |
-
logger.info(f"ํ์ฌ ์ฌ์ฉ์: {user_state}")
|
| 1701 |
-
|
| 1702 |
-
try:
|
| 1703 |
-
# ๋ก๊ทธ๋ผ์ธ ์ ํ ํ์ธ
|
| 1704 |
-
if not selected_logline_dropdown:
|
| 1705 |
-
selected_logline = current_state.get("loglines", [""])[0] if current_state.get("loglines") else ""
|
| 1706 |
-
logger.info("์ง์ ์คํ ๋ฆฌ ์์ฑ ๋ชจ๋")
|
| 1707 |
-
else:
|
| 1708 |
-
logline_num = int(selected_logline_dropdown.split(':')[0].split()[-1]) - 1
|
| 1709 |
-
selected_logline = current_state["loglines"][logline_num]
|
| 1710 |
-
logger.info(f"๋๋กญ๋ค์ด ์ ํ ๋ชจ๋ - ๋ก๊ทธ๋ผ์ธ ๋ฒํธ: {logline_num + 1}")
|
| 1711 |
-
|
| 1712 |
-
if not selected_logline:
|
| 1713 |
-
logger.error("์ ํ๋ ๋ก๊ทธ๋ผ์ธ์ด ์์")
|
| 1714 |
-
return gr.update(value="### โ ๏ธ ๋ก๊ทธ๋ผ์ธ์ ๋จผ์ ์ ํํด์ฃผ์ธ์"), gr.update(), None
|
| 1715 |
-
|
| 1716 |
-
logger.info(f"์ ํ๋ ๋ก๊ทธ๋ผ์ธ: {selected_logline[:50]}...")
|
| 1717 |
-
|
| 1718 |
-
# ์น์์ค ๊ตฌ์กฐ ์์ฑ
|
| 1719 |
-
system = WebNovelSystem()
|
| 1720 |
-
story = system.generate_story_structure(selected_logline, genre)
|
| 1721 |
-
logger.info(f"์คํ ๋ฆฌ ๊ตฌ์กฐ ์์ฑ ์๋ฃ - ์ ๋ชฉ: {story.title}")
|
| 1722 |
-
|
| 1723 |
-
# ์ธ์
์์ฑ
|
| 1724 |
-
session_id = WebNovelDatabase.create_session(
|
| 1725 |
-
user_id=user_state['user_id'],
|
| 1726 |
-
genre=genre,
|
| 1727 |
-
title=story.title,
|
| 1728 |
-
logline=selected_logline
|
| 1729 |
-
)
|
| 1730 |
-
logger.info(f"์ธ์
์์ฑ ์๋ฃ: {session_id}")
|
| 1731 |
-
|
| 1732 |
-
# ์คํ ๋ฆฌ ๊ตฌ์กฐ ์ ์ฅ
|
| 1733 |
-
WebNovelDatabase.save_story_structure(session_id, story)
|
| 1734 |
-
logger.info("์คํ ๋ฆฌ ๊ตฌ์กฐ DB ์ ์ฅ ์๋ฃ")
|
| 1735 |
-
|
| 1736 |
-
# ์ถ๋ ฅ ํฌ๋งท
|
| 1737 |
-
output = f"## ๐ญ {story.title}\n\n"
|
| 1738 |
-
output += f"**์๊ฐ:** {user_state.get('username', 'Unknown')}\n"
|
| 1739 |
-
output += f"**์ฅ๋ฅด:** {genre}\n\n"
|
| 1740 |
-
output += f"**์๋์์ค:**\n{story.synopsis}\n\n"
|
| 1741 |
-
output += f"### โ
40ํ ๊ตฌ์ฑ ์๋ฃ!\n\n"
|
| 1742 |
-
output += "์ด์ **1ํ ์์ฑ** ๋ฒํผ์ ํด๋ฆญํ์ฌ ์น์์ค์ ์์ํ์ธ์."
|
| 1743 |
-
|
| 1744 |
-
# ์ธ์
์ ๋ณด์ user_state ํฌํจ
|
| 1745 |
-
session_data = {
|
| 1746 |
-
"session_id": session_id,
|
| 1747 |
-
"story": story,
|
| 1748 |
-
"user_state": user_state # ์ ์ ์ ๋ณด ํฌํจ
|
| 1749 |
-
}
|
| 1750 |
-
|
| 1751 |
-
return (
|
| 1752 |
-
gr.update(value=output, visible=True),
|
| 1753 |
-
gr.update(visible=True),
|
| 1754 |
-
session_data
|
| 1755 |
-
)
|
| 1756 |
-
|
| 1757 |
-
except Exception as e:
|
| 1758 |
-
logger.error(f"์น์์ค ๊ตฌ์กฐ ์์ฑ ์ค๋ฅ: {str(e)}", exc_info=True)
|
| 1759 |
-
return gr.update(value=f"### โ ์ค๋ฅ\n\n{str(e)}"), gr.update(), None
|
| 1760 |
-
|
| 1761 |
-
|
| 1762 |
-
|
| 1763 |
-
def write_episode_handler(current_session, episode_num=1, request: gr.Request = None):
|
| 1764 |
-
"""Write an episode"""
|
| 1765 |
-
logger.info(f"=== ์ํผ์๋ ์์ฑ ์์ - {episode_num}ํ ===")
|
| 1766 |
-
|
| 1767 |
-
if not current_session:
|
| 1768 |
-
logger.error("current_session์ด None")
|
| 1769 |
-
return gr.update(value="### โ ๏ธ ์คํ ๋ฆฌ ๊ตฌ์ฑ์ ๋จผ์ ์์ฑํด์ฃผ์ธ์"), gr.update(), episode_num
|
| 1770 |
-
|
| 1771 |
-
# ์ธ์
์ ์ ์ฅ๋ user_state ์ฌ์ฉ ๋๋ request์์ ๊ฐ์ ธ์ค๊ธฐ
|
| 1772 |
-
user_state = current_session.get('user_state')
|
| 1773 |
-
if not user_state:
|
| 1774 |
-
user_state = get_user_state(request)
|
| 1775 |
-
|
| 1776 |
-
if not user_state:
|
| 1777 |
-
logger.error("์ ์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์")
|
| 1778 |
-
return gr.update(value="### โ ๏ธ ์ค๋ฅ\n\nํ์ด์ง๋ฅผ ์๋ก๊ณ ์นจํด์ฃผ์ธ์."), gr.update(), episode_num
|
| 1779 |
-
|
| 1780 |
-
logger.info(f"ํ์ฌ ์ฌ์ฉ์: {user_state}")
|
| 1781 |
-
|
| 1782 |
-
try:
|
| 1783 |
-
# ์ธ์
์ ๋ณด ํ์ธ
|
| 1784 |
-
session_id = current_session.get('session_id')
|
| 1785 |
-
if not session_id:
|
| 1786 |
-
logger.error("session_id๊ฐ ์์")
|
| 1787 |
-
return gr.update(value="### โ ๏ธ ์ธ์
์ ๋ณด๊ฐ ์์ต๋๋ค"), gr.update(), episode_num
|
| 1788 |
-
|
| 1789 |
-
# ์์ ๊ถ ํ์ธ
|
| 1790 |
-
logger.info(f"์์ ๊ถ ํ์ธ ์ค - session_id: {session_id}, user_id: {user_state['user_id']}")
|
| 1791 |
-
if not WebNovelDatabase.check_ownership(session_id, user_state['user_id']):
|
| 1792 |
-
logger.warning("์์ ๊ถ ์์")
|
| 1793 |
-
return gr.update(value="### โ ๏ธ ์ํ ์์ ๊ถ์ด ์์ต๋๋ค"), gr.update(), episode_num
|
| 1794 |
-
|
| 1795 |
-
logger.info("์์ ๊ถ ํ์ธ ์๋ฃ")
|
| 1796 |
-
|
| 1797 |
-
# ์ํผ์๋ ์์ฑ
|
| 1798 |
-
system = WebNovelSystem()
|
| 1799 |
-
previous_episodes = WebNovelDatabase.get_episodes(session_id)
|
| 1800 |
-
prev_contents = [ep['content'] for ep in previous_episodes]
|
| 1801 |
-
|
| 1802 |
-
story = current_session.get('story')
|
| 1803 |
-
if not story:
|
| 1804 |
-
logger.error("story ์ ๋ณด๊ฐ ์์")
|
| 1805 |
-
return gr.update(value="### โ ๏ธ ์คํ ๋ฆฌ ์ ๋ณด๊ฐ ์์ต๋๋ค"), gr.update(), episode_num
|
| 1806 |
-
|
| 1807 |
-
episode_data = system.write_episode(story, episode_num, prev_contents)
|
| 1808 |
-
logger.info(f"์ํผ์๋ ์์ฑ ์๋ฃ - {episode_data['word_count']} ๋จ์ด")
|
| 1809 |
-
|
| 1810 |
-
# DB ์ ์ฅ
|
| 1811 |
-
WebNovelDatabase.save_episode(
|
| 1812 |
-
session_id,
|
| 1813 |
-
episode_num,
|
| 1814 |
-
episode_data['title'],
|
| 1815 |
-
episode_data['content'],
|
| 1816 |
-
episode_data['hook']
|
| 1817 |
-
)
|
| 1818 |
-
|
| 1819 |
-
# ์ถ๋ ฅ ํฌ๋งท
|
| 1820 |
-
output = f"## {episode_data['title']}\n\n"
|
| 1821 |
-
output += episode_data['content']
|
| 1822 |
-
output += f"\n\n---\n"
|
| 1823 |
-
output += f"๐ **ํต๊ณ**\n"
|
| 1824 |
-
output += f"- ๋จ์ด ์: {episode_data['word_count']}\n"
|
| 1825 |
-
output += f"- ์งํ๋ฅ : {episode_num}/40ํ\n"
|
| 1826 |
-
output += f"- ์๊ฐ: {user_state.get('username', 'Unknown')}\n"
|
| 1827 |
-
output += f"\n๐ช **๋ค์ ํ ์๊ณ **\n> {episode_data['hook']}"
|
| 1828 |
-
|
| 1829 |
-
next_visible = episode_num < 40
|
| 1830 |
-
|
| 1831 |
-
return (
|
| 1832 |
-
gr.update(value=output, visible=True),
|
| 1833 |
-
gr.update(visible=next_visible),
|
| 1834 |
-
episode_num
|
| 1835 |
-
)
|
| 1836 |
-
|
| 1837 |
-
except Exception as e:
|
| 1838 |
-
logger.error(f"์ํผ์๋ ์์ฑ ์ค๋ฅ: {str(e)}", exc_info=True)
|
| 1839 |
-
return gr.update(value=f"### โ ์ค๋ฅ\n\n{str(e)}"), gr.update(), episode_num
|
| 1840 |
-
|
| 1841 |
-
|
| 1842 |
-
|
| 1843 |
-
def get_user_state(request: gr.Request) -> Optional[Dict[str, str]]:
|
| 1844 |
-
"""Request์์ ์ ์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ํฌํผ ํจ์"""
|
| 1845 |
-
if not request:
|
| 1846 |
-
# ๊ฐ๋ฐ ๋ชจ๋
|
| 1847 |
-
session_id = hashlib.md5(f"dev_{datetime.now()}_{random.randint(1000,9999)}".encode()).hexdigest()[:8]
|
| 1848 |
-
return {"user_id": f"dev_{session_id}", "username": f"๊ฐ๋ฐ์_{session_id}"}
|
| 1849 |
-
|
| 1850 |
-
# OAuth ํ์ธ
|
| 1851 |
-
if request.username:
|
| 1852 |
-
return {"user_id": request.username, "username": request.username}
|
| 1853 |
-
|
| 1854 |
-
# ํค๋ ํ์ธ (Hugging Face Spaces)
|
| 1855 |
-
if hasattr(request, 'headers'):
|
| 1856 |
-
user_info = request.headers.get('x-user-info', '')
|
| 1857 |
-
if user_info:
|
| 1858 |
-
return {"user_id": user_info, "username": user_info}
|
| 1859 |
-
|
| 1860 |
-
# ๊ฒ์คํธ ๋ชจ๋
|
| 1861 |
-
session_hash = getattr(request, 'session_hash', '')
|
| 1862 |
-
if session_hash:
|
| 1863 |
-
guest_id = f"guest_{session_hash[:8]}"
|
| 1864 |
-
return {"user_id": guest_id, "username": f"๊ฒ์คํธ_{session_hash[:8]}"}
|
| 1865 |
-
|
| 1866 |
-
# ์ตํ์ ์๋จ: ๋๋ค ๊ฒ์คํธ
|
| 1867 |
-
session_id = hashlib.md5(f"guest_{datetime.now()}_{random.randint(1000,9999)}".encode()).hexdigest()[:8]
|
| 1868 |
-
return {"user_id": f"guest_{session_id}", "username": f"๊ฒ์คํธ_{session_id}"}
|
| 1869 |
-
|
| 1870 |
-
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
| 1871 |
-
def write_next_episode(current_session, counter):
|
| 1872 |
-
"""๋ค์ ์ํผ์๋ ์์ฑ"""
|
| 1873 |
-
next_num = counter + 1
|
| 1874 |
-
result = write_episode_handler(current_session, next_num)
|
| 1875 |
-
return result[0], result[1], next_num
|
| 1876 |
-
|
| 1877 |
-
|
| 1878 |
-
|
| 1879 |
-
def load_library(user_state):
|
| 1880 |
-
"""Load user's novel library"""
|
| 1881 |
-
if not user_state:
|
| 1882 |
-
return "<p>๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค</p>", gr.update(), gr.update(), gr.update()
|
| 1883 |
-
|
| 1884 |
-
sessions = WebNovelDatabase.get_user_sessions(user_state['user_id'])
|
| 1885 |
-
|
| 1886 |
-
if not sessions:
|
| 1887 |
-
return "<p>์์ฑํ ์ํ์ด ์์ต๋๋ค</p>", gr.update(), gr.update(), gr.update()
|
| 1888 |
-
|
| 1889 |
-
# Create library HTML
|
| 1890 |
-
html = "<h3>๋ด ์ํ ๋ชฉ๋ก</h3>"
|
| 1891 |
-
html += "<table style='width:100%; border-collapse: collapse;'>"
|
| 1892 |
-
html += "<tr style='background-color: #f0f0f0;'>"
|
| 1893 |
-
html += "<th style='padding: 10px; border: 1px solid #ddd;'>์ ๋ชฉ</th>"
|
| 1894 |
-
html += "<th style='padding: 10px; border: 1px solid #ddd;'>์ฅ๋ฅด</th>"
|
| 1895 |
-
html += "<th style='padding: 10px; border: 1px solid #ddd;'>์งํ๋ฅ </th>"
|
| 1896 |
-
html += "<th style='padding: 10px; border: 1px solid #ddd;'>์ต๊ทผ ์์ </th>"
|
| 1897 |
-
html += "</tr>"
|
| 1898 |
-
|
| 1899 |
-
novel_choices = []
|
| 1900 |
-
for session in sessions:
|
| 1901 |
-
progress = f"{session['current_episode']}/{session['total_episodes']}ํ"
|
| 1902 |
-
html += f"<tr>"
|
| 1903 |
-
html += f"<td style='padding: 10px; border: 1px solid #ddd;'>{session['title'] or '์ ๋ชฉ ์์'}</td>"
|
| 1904 |
-
html += f"<td style='padding: 10px; border: 1px solid #ddd;'>{session['genre']}</td>"
|
| 1905 |
-
html += f"<td style='padding: 10px; border: 1px solid #ddd;'>{progress}</td>"
|
| 1906 |
-
html += f"<td style='padding: 10px; border: 1px solid #ddd;'>{session['updated_at'][:10]}</td>"
|
| 1907 |
-
html += f"</tr>"
|
| 1908 |
-
|
| 1909 |
-
novel_choices.append({
|
| 1910 |
-
"label": f"{session['title'] or '์ ๋ชฉ ์์'} ({session['genre']}) - {progress}",
|
| 1911 |
-
"value": session['session_id']
|
| 1912 |
-
})
|
| 1913 |
-
|
| 1914 |
-
html += "</table>"
|
| 1915 |
-
|
| 1916 |
-
return (
|
| 1917 |
-
html,
|
| 1918 |
-
gr.update(choices=novel_choices, visible=True),
|
| 1919 |
-
gr.update(visible=True),
|
| 1920 |
-
gr.update(visible=True)
|
| 1921 |
-
)
|
| 1922 |
-
|
| 1923 |
-
# Connect events
|
| 1924 |
-
interface.load(check_login, outputs=[login_status, user_state])
|
| 1925 |
-
|
| 1926 |
-
# Step 1: Logline generation (from paste.txt)
|
| 1927 |
-
random_btn.click(
|
| 1928 |
-
fn=lambda: generate_loglines_step("", gr.Progress()),
|
| 1929 |
-
inputs=[],
|
| 1930 |
-
outputs=[
|
| 1931 |
-
category_output,
|
| 1932 |
-
loglines_output,
|
| 1933 |
-
logline_dropdown,
|
| 1934 |
-
generate_story_btn,
|
| 1935 |
-
story_header
|
| 1936 |
-
],
|
| 1937 |
-
show_progress=True
|
| 1938 |
-
)
|
| 1939 |
-
|
| 1940 |
-
generate_btn.click(
|
| 1941 |
-
fn=lambda prompt: generate_loglines_step(prompt, gr.Progress()),
|
| 1942 |
-
inputs=[user_prompt_input],
|
| 1943 |
-
outputs=[
|
| 1944 |
-
category_output,
|
| 1945 |
-
loglines_output,
|
| 1946 |
-
logline_dropdown,
|
| 1947 |
-
generate_story_btn,
|
| 1948 |
-
story_header
|
| 1949 |
-
],
|
| 1950 |
-
show_progress=True
|
| 1951 |
-
)
|
| 1952 |
-
|
| 1953 |
-
generate_story_btn.click(
|
| 1954 |
-
fn=generate_story_from_selection,
|
| 1955 |
-
inputs=[logline_dropdown],
|
| 1956 |
-
outputs=[
|
| 1957 |
-
selected_logline_output,
|
| 1958 |
-
conflicts_output,
|
| 1959 |
-
story_arc_output,
|
| 1960 |
-
final_details_output
|
| 1961 |
-
]
|
| 1962 |
-
).then(
|
| 1963 |
-
fn=show_genre_after_story,
|
| 1964 |
-
inputs=[selected_logline_output, user_state], # user_state ์ถ๊ฐ
|
| 1965 |
-
outputs=[genre_select, generate_webnovel_btn, user_state] # user_state ์ถ๋ ฅ ์ถ๊ฐ
|
| 1966 |
-
)
|
| 1967 |
-
|
| 1968 |
-
# ์์ ๋ ์ฝ๋
|
| 1969 |
-
direct_story_btn.click(
|
| 1970 |
-
fn=lambda prompt: generate_direct_story(prompt, gr.Progress()),
|
| 1971 |
-
inputs=[user_prompt_input],
|
| 1972 |
-
outputs=[
|
| 1973 |
-
selected_logline_output,
|
| 1974 |
-
conflicts_output,
|
| 1975 |
-
story_arc_output,
|
| 1976 |
-
final_details_output
|
| 1977 |
-
],
|
| 1978 |
-
show_progress=True
|
| 1979 |
-
).then(
|
| 1980 |
-
fn=show_genre_after_story,
|
| 1981 |
-
inputs=[selected_logline_output, user_state], # user_state ์ถ๊ฐ
|
| 1982 |
-
outputs=[genre_select, generate_webnovel_btn, user_state] # user_state ์ถ๋ ฅ ์ถ๊ฐ
|
| 1983 |
-
)
|
| 1984 |
-
|
| 1985 |
-
|
| 1986 |
-
# Step 2-3: Web novel generation
|
| 1987 |
-
generate_webnovel_btn.click(
|
| 1988 |
-
generate_webnovel_structure,
|
| 1989 |
-
inputs=[logline_dropdown, genre_select],
|
| 1990 |
-
outputs=[webnovel_structure_output, write_first_btn, current_session]
|
| 1991 |
-
)
|
| 1992 |
-
write_first_btn.click(
|
| 1993 |
-
lambda cs: write_episode_handler(cs, 1),
|
| 1994 |
-
inputs=[current_session],
|
| 1995 |
-
outputs=[episode_output, write_next_btn, episode_counter]
|
| 1996 |
-
)
|
| 1997 |
-
|
| 1998 |
-
|
| 1999 |
-
write_next_btn.click(
|
| 2000 |
-
write_next_episode,
|
| 2001 |
-
inputs=[current_session, episode_counter],
|
| 2002 |
-
outputs=[episode_output, write_next_btn, episode_counter]
|
| 2003 |
-
)
|
| 2004 |
-
|
| 2005 |
-
# Library
|
| 2006 |
-
refresh_library_btn.click(
|
| 2007 |
-
load_library,
|
| 2008 |
-
inputs=[user_state],
|
| 2009 |
-
outputs=[library_output, selected_novel, continue_writing_btn, preview_btn]
|
| 2010 |
-
)
|
| 2011 |
-
|
| 2012 |
-
return interface
|
| 2013 |
-
|
| 2014 |
-
# Main
|
| 2015 |
-
if __name__ == "__main__":
|
| 2016 |
-
logger.info("K-Story AI Studio Starting...")
|
| 2017 |
-
logger.info("=" * 60)
|
| 2018 |
-
|
| 2019 |
-
# Environment check
|
| 2020 |
-
if not FRIENDLI_TOKEN:
|
| 2021 |
-
logger.warning("FRIENDLI_TOKEN not set. Using dummy token for testing.")
|
| 2022 |
-
|
| 2023 |
-
# Initialize database
|
| 2024 |
-
WebNovelDatabase.init_db()
|
| 2025 |
-
logger.info("Database initialized.")
|
| 2026 |
-
|
| 2027 |
-
# Launch interface
|
| 2028 |
-
interface = create_interface()
|
| 2029 |
-
interface.launch(
|
| 2030 |
-
server_name="0.0.0.0",
|
| 2031 |
-
server_port=7860,
|
| 2032 |
-
share=False
|
| 2033 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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