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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
20 |
+
# --- ๋ก๊น
์ค์ ---
|
21 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
22 |
+
logger = logging.getLogger(__name__)
|
23 |
+
|
24 |
+
# --- ํ๊ฒฝ ๋ณ์ ๋ฐ ์์ ---
|
25 |
+
FIREWORKS_API_KEY = os.getenv("FIREWORKS_API_KEY", "")
|
26 |
+
BRAVE_SEARCH_API_KEY = os.getenv("BRAVE_SEARCH_API_KEY", "")
|
27 |
+
API_URL = "https://api.fireworks.ai/inference/v1/chat/completions"
|
28 |
+
MODEL_ID = "accounts/fireworks/models/qwen3-235b-a22b-instruct-2507"
|
29 |
+
BRAVE_SEARCH_URL = "https://api.search.brave.com/res/v1/web/search"
|
30 |
+
DB_PATH = "screenplay_sessions_korean.db"
|
31 |
+
|
32 |
+
# ์๋๋ฆฌ์ค ๊ธธ์ด ์ค์
|
33 |
+
SCREENPLAY_LENGTHS = {
|
34 |
+
"์ํ": {"pages": 120, "description": "์ฅํธ ์ํ (110-130ํ์ด์ง)", "min_pages": 110},
|
35 |
+
"๋๋ผ๋ง": {"pages": 60, "description": "TV ๋๋ผ๋ง (55-65ํ์ด์ง)", "min_pages": 55},
|
36 |
+
"์น๋๋ผ๋ง": {"pages": 50, "description": "์น/OTT ์๋ฆฌ์ฆ (45-55ํ์ด์ง)", "min_pages": 45},
|
37 |
+
"๋จํธ": {"pages": 20, "description": "๋จํธ ์ํ (15-25ํ์ด์ง)", "min_pages": 15}
|
38 |
+
}
|
39 |
+
|
40 |
+
# ํ๊ฒฝ ๊ฒ์ฆ
|
41 |
+
if not FIREWORKS_API_KEY:
|
42 |
+
logger.error("FIREWORKS_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
43 |
+
FIREWORKS_API_KEY = "dummy_token_for_testing"
|
44 |
+
|
45 |
+
# ๊ธ๋ก๋ฒ ๋ณ์
|
46 |
+
db_lock = threading.Lock()
|
47 |
+
|
48 |
+
# ์ ๋ฌธ๊ฐ ์ญํ ์ ์
|
49 |
+
EXPERT_ROLES = {
|
50 |
+
"ํ๋ก๋์": {
|
51 |
+
"emoji": "๐ฌ",
|
52 |
+
"description": "์์
์ฑ๊ณผ ์์ฅ์ฑ ๋ถ์",
|
53 |
+
"focus": ["ํ๊ฒ ๊ด๊ฐ", "์ ์ ๊ฐ๋ฅ์ฑ", "์์ฐ ๊ท๋ชจ", "๋ง์ผํ
ํฌ์ธํธ"],
|
54 |
+
"personality": "์ค์ฉ์ ์ด๊ณ ์์ฅ ์งํฅ์ "
|
55 |
+
},
|
56 |
+
"์คํ ๋ฆฌ์๊ฐ": {
|
57 |
+
"emoji": "๐",
|
58 |
+
"description": "๋ด๋ฌํฐ๋ธ ๊ตฌ์กฐ์ ํ๋กฏ ๊ฐ๋ฐ",
|
59 |
+
"focus": ["3๋ง ๊ตฌ์กฐ", "ํ๋กฏ ํฌ์ธํธ", "์์ฌ ์ํฌ", "ํ
๋ง"],
|
60 |
+
"personality": "์ฐฝ์์ ์ด๊ณ ๊ตฌ์กฐ์ "
|
61 |
+
},
|
62 |
+
"์บ๋ฆญํฐ๋์์ด๋": {
|
63 |
+
"emoji": "๐ฅ",
|
64 |
+
"description": "์ธ๋ฌผ ์ฐฝ์กฐ์ ๊ด๊ณ ์ค๊ณ",
|
65 |
+
"focus": ["์บ๋ฆญํฐ ์ํฌ", "๋๊ธฐ๋ถ์ฌ", "๊ด๊ณ ์ญํ", "๋ํ ์คํ์ผ"],
|
66 |
+
"personality": "์ฌ๋ฆฌํ์ ์ด๊ณ ๊ณต๊ฐ์ "
|
67 |
+
},
|
68 |
+
"๊ฐ๋
": {
|
69 |
+
"emoji": "๐ญ",
|
70 |
+
"description": "๋น์ฃผ์ผ ์คํ ๋ฆฌํ
๋ง๊ณผ ์ฐ์ถ",
|
71 |
+
"focus": ["์๊ฐ์ ๊ตฌ์ฑ", "์นด๋ฉ๋ผ ์ํฌ", "๋ฏธ์ฅ์ผ", "๋ฆฌ๋ฌ๊ณผ ํ์ด์ฑ"],
|
72 |
+
"personality": "๋น์ฃผ์ผ ์ค์ฌ์ ์ด๊ณ ์์ ์ "
|
73 |
+
},
|
74 |
+
"๊ณ ์ฆ์ ๋ฌธ๊ฐ": {
|
75 |
+
"emoji": "๐",
|
76 |
+
"description": "์ฌ์ค ํ์ธ๊ณผ ๊ณ ์ฆ",
|
77 |
+
"focus": ["์ญ์ฌ์ ์ ํ์ฑ", "๊ณผํ์ ํ๋น์ฑ", "๋ฌธํ์ ์ ์ ์ฑ", "ํ์ค์ฑ"],
|
78 |
+
"personality": "์ ํํ๊ณ ์ธ์ฌํ"
|
79 |
+
},
|
80 |
+
"๋นํ๊ฐ": {
|
81 |
+
"emoji": "๐",
|
82 |
+
"description": "๊ฐ๊ด์ ๋ถ์๊ณผ ๊ฐ์ ์ ์ ์",
|
83 |
+
"focus": ["๋
ผ๋ฆฌ์ ์ผ๊ด์ฑ", "๊ฐ์ ์ ์ํฉํธ", "์์ ์ถฉ์ค๋", "์์ฑ๋"],
|
84 |
+
"personality": "๋ถ์์ ์ด๊ณ ๋นํ์ "
|
85 |
+
},
|
86 |
+
"ํธ์ง์": {
|
87 |
+
"emoji": "โ๏ธ",
|
88 |
+
"description": "ํ์ด์ฑ๊ณผ ๊ตฌ์กฐ ์ต์ ํ",
|
89 |
+
"focus": ["์ฌ ์ ํ", "๋ฆฌ๋ฌ", "๊ธด์ฅ๊ฐ ์กฐ์ ", "๋ถํ์ํ ๋ถ๋ถ ์ ๊ฑฐ"],
|
90 |
+
"personality": "์ ๋ฐํ๊ณ ํจ์จ์ "
|
91 |
+
},
|
92 |
+
"๋ํ์ ๋ฌธ๊ฐ": {
|
93 |
+
"emoji": "๐ฌ",
|
94 |
+
"description": "๋์ฌ์ ์๋ธํ
์คํธ ๊ฐํ",
|
95 |
+
"focus": ["์์ฐ์ค๋ฌ์ด ๋ํ", "์บ๋ฆญํฐ ๋ณด์ด์ค", "์๋ธํ
์คํธ", "๊ฐ์ ์ ๋ฌ"],
|
96 |
+
"personality": "์ธ์ด์ ์ด๊ณ ๋์์ค ์ค์ฌ"
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
# ๋ง๋ณ ์์ฑ ๋จ๊ณ
|
101 |
+
ACT_WRITING_STAGES = {
|
102 |
+
"1๋ง": [
|
103 |
+
("์คํ ๋ฆฌ์๊ฐ", "์ด๊ณ ", "โ๏ธ ์คํ ๋ฆฌ์๊ฐ: 1๋ง ์ด๊ณ ์์ฑ"),
|
104 |
+
("๊ณ ์ฆ์ ๋ฌธ๊ฐ", "๊ฒ์ฆ", "๐ ๊ณ ์ฆ์ ๋ฌธ๊ฐ: ์ฌ์ค ํ์ธ ๋ฐ ๊ฒ์ฆ"),
|
105 |
+
("ํธ์ง์", "ํธ์ง", "โ๏ธ ํธ์ง์: ๊ตฌ์กฐ ๋ฐ ํ์ด์ฑ ์กฐ์ "),
|
106 |
+
("๊ฐ๋
", "์ฐ์ถ", "๐ญ ๊ฐ๋
: ๋น์ฃผ์ผ ๊ฐํ ๋ฐ ์ฐ์ถ ๋
ธํธ"),
|
107 |
+
("๋ํ์ ๋ฌธ๊ฐ", "๋์ฌ", "๐ฌ ๋ํ์ ๋ฌธ๊ฐ: ๋์ฌ ๊ฐ์ "),
|
108 |
+
("๋นํ๊ฐ", "๊ฒํ ", "๐ ๋นํ๊ฐ: ์ข
ํฉ ๊ฒํ ๋ฐ ํ๊ฐ"),
|
109 |
+
("์คํ ๋ฆฌ์๊ฐ", "์์ฑ", "โ
์คํ ๋ฆฌ์๊ฐ: 1๋ง ์ต์ข
์์ฑ")
|
110 |
+
],
|
111 |
+
"2๋งA": [
|
112 |
+
("์คํ ๋ฆฌ์๊ฐ", "์ด๊ณ ", "โ๏ธ ์คํ ๋ฆฌ์๊ฐ: 2๋งA ์ด๊ณ ์์ฑ"),
|
113 |
+
("๊ณ ์ฆ์ ๋ฌธ๊ฐ", "๊ฒ์ฆ", "๐ ๊ณ ์ฆ์ ๋ฌธ๊ฐ: ์ฌ์ค ํ์ธ ๋ฐ ๊ฒ์ฆ"),
|
114 |
+
("ํธ์ง์", "ํธ์ง", "โ๏ธ ํธ์ง์: ๊ตฌ์กฐ ๋ฐ ํ์ด์ฑ ์กฐ์ "),
|
115 |
+
("๊ฐ๋
", "์ฐ์ถ", "๐ญ ๊ฐ๋
: ๋น์ฃผ์ผ ๊ฐํ ๋ฐ ์ฐ์ถ ๋
ธํธ"),
|
116 |
+
("๋ํ์ ๋ฌธ๊ฐ", "๋์ฌ", "๐ฌ ๋ํ์ ๋ฌธ๊ฐ: ๋์ฌ ๊ฐ์ "),
|
117 |
+
("๋นํ๊ฐ", "๊ฒํ ", "๐ ๋นํ๊ฐ: ์ข
ํฉ ๊ฒํ ๋ฐ ํ๊ฐ"),
|
118 |
+
("์คํ ๋ฆฌ์๊ฐ", "์์ฑ", "โ
์คํ ๋ฆฌ์๊ฐ: 2๋งA ์ต์ข
์์ฑ")
|
119 |
+
],
|
120 |
+
"2๋งB": [
|
121 |
+
("์คํ ๋ฆฌ์๊ฐ", "์ด๊ณ ", "โ๏ธ ์คํ ๋ฆฌ์๊ฐ: 2๋งB ์ด๊ณ ์์ฑ"),
|
122 |
+
("๊ณ ์ฆ์ ๋ฌธ๊ฐ", "๊ฒ์ฆ", "๐ ๊ณ ์ฆ์ ๋ฌธ๊ฐ: ์ฌ์ค ํ์ธ ๋ฐ ๊ฒ์ฆ"),
|
123 |
+
("ํธ์ง์", "ํธ์ง", "โ๏ธ ํธ์ง์: ๊ตฌ์กฐ ๋ฐ ํ์ด์ฑ ์กฐ์ "),
|
124 |
+
("๊ฐ๋
", "์ฐ์ถ", "๐ญ ๊ฐ๋
: ๋น์ฃผ์ผ ๊ฐํ ๋ฐ ์ฐ์ถ ๋
ธํธ"),
|
125 |
+
("๋ํ์ ๋ฌธ๊ฐ", "๋์ฌ", "๐ฌ ๋ํ์ ๋ฌธ๊ฐ: ๋์ฌ ๊ฐ์ "),
|
126 |
+
("๋นํ๊ฐ", "๊ฒํ ", "๐ ๋นํ๊ฐ: ์ข
ํฉ ๊ฒํ ๋ฐ ํ๊ฐ"),
|
127 |
+
("์คํ ๋ฆฌ์๊ฐ", "์์ฑ", "โ
์คํ ๋ฆฌ์๊ฐ: 2๋งB ์ต์ข
์์ฑ")
|
128 |
+
],
|
129 |
+
"3๋ง": [
|
130 |
+
("์คํ ๋ฆฌ์๊ฐ", "์ด๊ณ ", "โ๏ธ ์คํ ๋ฆฌ์๊ฐ: 3๋ง ์ด๊ณ ์์ฑ"),
|
131 |
+
("๊ณ ์ฆ์ ๋ฌธ๊ฐ", "๊ฒ์ฆ", "๐ ๊ณ ์ฆ์ ๋ฌธ๊ฐ: ์ฌ์ค ํ์ธ ๋ฐ ๊ฒ์ฆ"),
|
132 |
+
("ํธ์ง์", "ํธ์ง", "โ๏ธ ํธ์ง์: ๊ตฌ์กฐ ๋ฐ ํ์ด์ฑ ์กฐ์ "),
|
133 |
+
("๊ฐ๋
", "์ฐ์ถ", "๐ญ ๊ฐ๋
: ๋น์ฃผ์ผ ๊ฐํ ๋ฐ ์ฐ์ถ ๋
ธํธ"),
|
134 |
+
("๋ํ์ ๋ฌธ๊ฐ", "๋์ฌ", "๐ฌ ๋ํ์ ๋ฌธ๊ฐ: ๋์ฌ ๊ฐ์ "),
|
135 |
+
("๋นํ๊ฐ", "๊ฒํ ", "๐ ๋นํ๊ฐ: ์ข
ํฉ ๊ฒํ ๋ฐ ํ๊ฐ"),
|
136 |
+
("์คํ ๋ฆฌ์๊ฐ", "์์ฑ", "โ
์คํ ๋ฆฌ์๊ฐ: 3๋ง ์ต์ข
์์ฑ")
|
137 |
+
]
|
138 |
+
}
|
139 |
+
|
140 |
+
# ์น ๊ฒ์ ํด๋์ค
|
141 |
+
class WebSearcher:
|
142 |
+
"""์ฌ์ค ํ์ธ๊ณผ ๊ณ ์ฆ์ ์ํ ์น ๊ฒ์"""
|
143 |
+
def __init__(self):
|
144 |
+
self.api_key = BRAVE_SEARCH_API_KEY
|
145 |
+
self.enabled = bool(self.api_key)
|
146 |
+
|
147 |
+
def search(self, query: str, count: int = 3) -> List[Dict]:
|
148 |
+
"""์น ๊ฒ์ ์ํ"""
|
149 |
+
if not self.enabled:
|
150 |
+
return []
|
151 |
+
|
152 |
+
headers = {
|
153 |
+
"Accept": "application/json",
|
154 |
+
"X-Subscription-Token": self.api_key
|
155 |
+
}
|
156 |
+
|
157 |
+
params = {
|
158 |
+
"q": query,
|
159 |
+
"count": count,
|
160 |
+
"search_lang": "ko",
|
161 |
+
"safesearch": "moderate"
|
162 |
+
}
|
163 |
+
|
164 |
+
try:
|
165 |
+
response = requests.get(BRAVE_SEARCH_URL, headers=headers, params=params, timeout=10)
|
166 |
+
if response.status_code == 200:
|
167 |
+
results = response.json().get("web", {}).get("results", [])
|
168 |
+
return results
|
169 |
+
else:
|
170 |
+
logger.error(f"Search API error: {response.status_code}")
|
171 |
+
return []
|
172 |
+
except Exception as e:
|
173 |
+
logger.error(f"Search error: {e}")
|
174 |
+
return []
|
175 |
+
|
176 |
+
def verify_facts(self, content: str, context: str) -> Dict:
|
177 |
+
"""๋ด์ฉ์ ์ฌ์ค ํ์ธ"""
|
178 |
+
verification_results = {
|
179 |
+
"verified": [],
|
180 |
+
"needs_correction": [],
|
181 |
+
"suggestions": []
|
182 |
+
}
|
183 |
+
|
184 |
+
# ์ฃผ์ ํค์๋ ์ถ์ถ
|
185 |
+
keywords = self._extract_keywords(content)
|
186 |
+
|
187 |
+
for keyword in keywords[:3]: # ์์ 3๊ฐ๋ง ๊ฒ์
|
188 |
+
search_query = f"{keyword} {context} ์ฌ์ค ํ์ธ"
|
189 |
+
results = self.search(search_query, count=2)
|
190 |
+
|
191 |
+
if results:
|
192 |
+
verification_results["verified"].append({
|
193 |
+
"keyword": keyword,
|
194 |
+
"sources": [r["title"] for r in results]
|
195 |
+
})
|
196 |
+
|
197 |
+
return verification_results
|
198 |
+
|
199 |
+
def _extract_keywords(self, content: str) -> List[str]:
|
200 |
+
"""์ฃผ์ ํค์๋ ์ถ์ถ"""
|
201 |
+
# ๊ฐ๋จํ ํค์๋ ์ถ์ถ (์ค์ ๋ก๋ ๋ ์ ๊ตํ ๋ฐฉ๋ฒ ํ์)
|
202 |
+
words = content.split()
|
203 |
+
keywords = [w for w in words if len(w) > 4][:5]
|
204 |
+
return keywords
|
205 |
+
|
206 |
+
# ๋ฐ์ดํฐ ํด๋์ค
|
207 |
+
@dataclass
|
208 |
+
class ExpertFeedback:
|
209 |
+
"""์ ๋ฌธ๊ฐ ํผ๋๋ฐฑ"""
|
210 |
+
role: str
|
211 |
+
stage: str
|
212 |
+
feedback: str
|
213 |
+
suggestions: List[str]
|
214 |
+
score: float
|
215 |
+
timestamp: datetime = field(default_factory=datetime.now)
|
216 |
+
|
217 |
+
@dataclass
|
218 |
+
class ActProgress:
|
219 |
+
"""๋ง๋ณ ์งํ ์ํฉ"""
|
220 |
+
act_name: str
|
221 |
+
current_stage: int
|
222 |
+
total_stages: int
|
223 |
+
current_expert: str
|
224 |
+
status: str # "ready", "in_progress", "complete"
|
225 |
+
content: str = ""
|
226 |
+
expert_feedbacks: List[ExpertFeedback] = field(default_factory=list)
|
227 |
+
|
228 |
+
@property
|
229 |
+
def progress_percentage(self):
|
230 |
+
if self.total_stages == 0:
|
231 |
+
return 0
|
232 |
+
return (self.current_stage / self.total_stages) * 100
|
233 |
+
|
234 |
+
# ๋ฐ์ดํฐ๋ฒ ์ด์ค ํด๋์ค
|
235 |
+
class ScreenplayDatabase:
|
236 |
+
@staticmethod
|
237 |
+
def init_db():
|
238 |
+
with sqlite3.connect(DB_PATH) as conn:
|
239 |
+
conn.execute("PRAGMA journal_mode=WAL")
|
240 |
+
cursor = conn.cursor()
|
241 |
+
|
242 |
+
cursor.execute('''
|
243 |
+
CREATE TABLE IF NOT EXISTS screenplay_sessions (
|
244 |
+
session_id TEXT PRIMARY KEY,
|
245 |
+
user_query TEXT NOT NULL,
|
246 |
+
screenplay_type TEXT NOT NULL,
|
247 |
+
genre TEXT NOT NULL,
|
248 |
+
target_pages INTEGER,
|
249 |
+
title TEXT,
|
250 |
+
logline TEXT,
|
251 |
+
planning_data TEXT,
|
252 |
+
act1_content TEXT,
|
253 |
+
act2a_content TEXT,
|
254 |
+
act2b_content TEXT,
|
255 |
+
act3_content TEXT,
|
256 |
+
expert_feedbacks TEXT,
|
257 |
+
created_at TEXT DEFAULT (datetime('now')),
|
258 |
+
updated_at TEXT DEFAULT (datetime('now')),
|
259 |
+
status TEXT DEFAULT 'planning',
|
260 |
+
current_act TEXT DEFAULT '1๋ง',
|
261 |
+
total_pages REAL DEFAULT 0
|
262 |
+
)
|
263 |
+
''')
|
264 |
+
|
265 |
+
cursor.execute('''
|
266 |
+
CREATE TABLE IF NOT EXISTS act_progress (
|
267 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
268 |
+
session_id TEXT NOT NULL,
|
269 |
+
act_name TEXT NOT NULL,
|
270 |
+
stage_num INTEGER,
|
271 |
+
expert_role TEXT,
|
272 |
+
content TEXT,
|
273 |
+
feedback TEXT,
|
274 |
+
score REAL,
|
275 |
+
created_at TEXT DEFAULT (datetime('now')),
|
276 |
+
FOREIGN KEY (session_id) REFERENCES screenplay_sessions(session_id)
|
277 |
+
)
|
278 |
+
''')
|
279 |
+
|
280 |
+
conn.commit()
|
281 |
+
|
282 |
+
@staticmethod
|
283 |
+
@contextmanager
|
284 |
+
def get_db():
|
285 |
+
with db_lock:
|
286 |
+
conn = sqlite3.connect(DB_PATH, timeout=30.0)
|
287 |
+
conn.row_factory = sqlite3.Row
|
288 |
+
try:
|
289 |
+
yield conn
|
290 |
+
finally:
|
291 |
+
conn.close()
|
292 |
+
|
293 |
+
@staticmethod
|
294 |
+
def create_session(user_query: str, screenplay_type: str, genre: str) -> str:
|
295 |
+
session_id = hashlib.md5(f"{user_query}{screenplay_type}{datetime.now()}".encode()).hexdigest()
|
296 |
+
target_pages = SCREENPLAY_LENGTHS[screenplay_type]["pages"]
|
297 |
+
|
298 |
+
with ScreenplayDatabase.get_db() as conn:
|
299 |
+
conn.cursor().execute(
|
300 |
+
'''INSERT INTO screenplay_sessions
|
301 |
+
(session_id, user_query, screenplay_type, genre, target_pages)
|
302 |
+
VALUES (?, ?, ?, ?, ?)''',
|
303 |
+
(session_id, user_query, screenplay_type, genre, target_pages)
|
304 |
+
)
|
305 |
+
conn.commit()
|
306 |
+
return session_id
|
307 |
+
|
308 |
+
@staticmethod
|
309 |
+
def save_act_content(session_id: str, act_name: str, content: str):
|
310 |
+
"""๋ง๋ณ ์ฝํ
์ธ ์ ์ฅ"""
|
311 |
+
act_column = {
|
312 |
+
"1๋ง": "act1_content",
|
313 |
+
"2๋งA": "act2a_content",
|
314 |
+
"2๋งB": "act2b_content",
|
315 |
+
"3๋ง": "act3_content"
|
316 |
+
}.get(act_name, "act1_content")
|
317 |
+
|
318 |
+
with ScreenplayDatabase.get_db() as conn:
|
319 |
+
conn.cursor().execute(
|
320 |
+
f'''UPDATE screenplay_sessions
|
321 |
+
SET {act_column} = ?, current_act = ?, updated_at = datetime('now')
|
322 |
+
WHERE session_id = ?''',
|
323 |
+
(content, act_name, session_id)
|
324 |
+
)
|
325 |
+
conn.commit()
|
326 |
+
|
327 |
+
@staticmethod
|
328 |
+
def save_act_progress(session_id: str, act_name: str, stage_num: int,
|
329 |
+
expert_role: str, content: str, feedback: str, score: float):
|
330 |
+
"""๋ง๋ณ ์งํ ์ํฉ ์ ์ฅ"""
|
331 |
+
with ScreenplayDatabase.get_db() as conn:
|
332 |
+
conn.cursor().execute(
|
333 |
+
'''INSERT INTO act_progress
|
334 |
+
(session_id, act_name, stage_num, expert_role, content, feedback, score)
|
335 |
+
VALUES (?, ?, ?, ?, ?, ?, ?)''',
|
336 |
+
(session_id, act_name, stage_num, expert_role, content, feedback, score)
|
337 |
+
)
|
338 |
+
conn.commit()
|
339 |
+
|
340 |
+
@staticmethod
|
341 |
+
def get_session_data(session_id: str) -> Optional[Dict]:
|
342 |
+
"""์ธ์
๋ฐ์ดํฐ ์กฐํ"""
|
343 |
+
with ScreenplayDatabase.get_db() as conn:
|
344 |
+
row = conn.cursor().execute(
|
345 |
+
'SELECT * FROM screenplay_sessions WHERE session_id = ?',
|
346 |
+
(session_id,)
|
347 |
+
).fetchone()
|
348 |
+
if row:
|
349 |
+
return dict(row)
|
350 |
+
return None
|
351 |
+
|
352 |
+
# ์๋๋ฆฌ์ค ์์ฑ ์์คํ
|
353 |
+
class ScreenplayGenerationSystem:
|
354 |
+
def __init__(self):
|
355 |
+
self.api_key = FIREWORKS_API_KEY
|
356 |
+
self.api_url = API_URL
|
357 |
+
self.model_id = MODEL_ID
|
358 |
+
self.current_session_id = None
|
359 |
+
self.original_query = ""
|
360 |
+
self.planning_data = {}
|
361 |
+
self.web_searcher = WebSearcher()
|
362 |
+
self.current_act_progress = None
|
363 |
+
ScreenplayDatabase.init_db()
|
364 |
+
|
365 |
+
def create_headers(self):
|
366 |
+
if not self.api_key or self.api_key == "dummy_token_for_testing":
|
367 |
+
raise ValueError("์ ํจํ FIREWORKS_API_KEY๊ฐ ํ์ํฉ๋๋ค")
|
368 |
+
|
369 |
+
return {
|
370 |
+
"Accept": "application/json",
|
371 |
+
"Content-Type": "application/json",
|
372 |
+
"Authorization": f"Bearer {self.api_key}"
|
373 |
+
}
|
374 |
+
|
375 |
+
def call_llm_streaming(self, messages: List[Dict[str, str]], max_tokens: int = 8000) -> Generator[str, None, None]:
|
376 |
+
try:
|
377 |
+
payload = {
|
378 |
+
"model": self.model_id,
|
379 |
+
"messages": messages,
|
380 |
+
"max_tokens": max_tokens,
|
381 |
+
"temperature": 0.7,
|
382 |
+
"top_p": 0.9,
|
383 |
+
"top_k": 40,
|
384 |
+
"presence_penalty": 0.3,
|
385 |
+
"frequency_penalty": 0.3,
|
386 |
+
"stream": True
|
387 |
+
}
|
388 |
+
|
389 |
+
headers = self.create_headers()
|
390 |
+
|
391 |
+
response = requests.post(
|
392 |
+
self.api_url,
|
393 |
+
headers=headers,
|
394 |
+
json=payload,
|
395 |
+
stream=True,
|
396 |
+
timeout=300
|
397 |
+
)
|
398 |
+
|
399 |
+
if response.status_code != 200:
|
400 |
+
yield f"โ API ์ค๋ฅ: {response.status_code}"
|
401 |
+
return
|
402 |
+
|
403 |
+
buffer = ""
|
404 |
+
for line in response.iter_lines():
|
405 |
+
if not line:
|
406 |
+
continue
|
407 |
+
|
408 |
+
try:
|
409 |
+
line_str = line.decode('utf-8').strip()
|
410 |
+
if not line_str.startswith("data: "):
|
411 |
+
continue
|
412 |
+
|
413 |
+
data_str = line_str[6:]
|
414 |
+
if data_str == "[DONE]":
|
415 |
+
break
|
416 |
+
|
417 |
+
data = json.loads(data_str)
|
418 |
+
if "choices" in data and len(data["choices"]) > 0:
|
419 |
+
content = data["choices"][0].get("delta", {}).get("content", "")
|
420 |
+
if content:
|
421 |
+
buffer += content
|
422 |
+
if len(buffer) >= 100 or '\n' in buffer:
|
423 |
+
yield buffer
|
424 |
+
buffer = ""
|
425 |
+
except:
|
426 |
+
continue
|
427 |
+
|
428 |
+
if buffer:
|
429 |
+
yield buffer
|
430 |
+
|
431 |
+
except Exception as e:
|
432 |
+
yield f"โ ์ค๋ฅ: {str(e)}"
|
433 |
+
|
434 |
+
def generate_act(self, session_id: str, act_name: str, planning_data: Dict,
|
435 |
+
previous_acts: Dict) -> Generator[Tuple[ActProgress, str], None, None]:
|
436 |
+
"""๋ง๋ณ ์๋๋ฆฌ์ค ์์ฑ - ์ ๋ฌธ๊ฐ ํ์
"""
|
437 |
+
|
438 |
+
self.current_session_id = session_id
|
439 |
+
self.planning_data = planning_data
|
440 |
+
|
441 |
+
stages = ACT_WRITING_STAGES.get(act_name, [])
|
442 |
+
act_progress = ActProgress(
|
443 |
+
act_name=act_name,
|
444 |
+
current_stage=0,
|
445 |
+
total_stages=len(stages),
|
446 |
+
current_expert="",
|
447 |
+
status="in_progress"
|
448 |
+
)
|
449 |
+
|
450 |
+
act_content = ""
|
451 |
+
|
452 |
+
for idx, (role, stage_type, description) in enumerate(stages):
|
453 |
+
act_progress.current_stage = idx + 1
|
454 |
+
act_progress.current_expert = role
|
455 |
+
|
456 |
+
# ์งํ ์ํฉ ์
๋ฐ์ดํธ
|
457 |
+
yield act_progress, f"๐ {description} ์งํ ์ค..."
|
458 |
+
|
459 |
+
# ์ญํ ๋ณ ํ๋กฌํํธ ์์ฑ
|
460 |
+
if role == "์คํ ๋ฆฌ์๊ฐ":
|
461 |
+
prompt = self._create_writer_prompt(act_name, planning_data, previous_acts, stage_type)
|
462 |
+
elif role == "๊ณ ์ฆ์ ๋ฌธ๊ฐ":
|
463 |
+
prompt = self._create_verification_prompt(act_name, act_content)
|
464 |
+
elif role == "ํธ์ง์":
|
465 |
+
prompt = self._create_editor_prompt(act_name, act_content)
|
466 |
+
elif role == "๊ฐ๋
":
|
467 |
+
prompt = self._create_director_prompt(act_name, act_content)
|
468 |
+
elif role == "๋ํ์ ๋ฌธ๊ฐ":
|
469 |
+
prompt = self._create_dialogue_prompt(act_name, act_content)
|
470 |
+
elif role == "๋นํ๊ฐ":
|
471 |
+
prompt = self._create_critic_prompt(act_name, act_content)
|
472 |
+
else:
|
473 |
+
continue
|
474 |
+
|
475 |
+
# LLM ํธ์ถ
|
476 |
+
expert_info = EXPERT_ROLES[role]
|
477 |
+
messages = [
|
478 |
+
{"role": "system", "content": f"""๋น์ ์ {role}์
๋๋ค.
|
479 |
+
{expert_info['description']}
|
480 |
+
์ ๋ฌธ ๋ถ์ผ: {', '.join(expert_info['focus'])}"""},
|
481 |
+
{"role": "user", "content": prompt}
|
482 |
+
]
|
483 |
+
|
484 |
+
expert_output = ""
|
485 |
+
for chunk in self.call_llm_streaming(messages, max_tokens=10000):
|
486 |
+
expert_output += chunk
|
487 |
+
|
488 |
+
# ์ค์๊ฐ ์
๋ฐ์ดํธ
|
489 |
+
yield act_progress, f"โ๏ธ {role}: {expert_output[:100]}..."
|
490 |
+
|
491 |
+
# ์น ๊ฒ์์ ํตํ ๊ณ ์ฆ (๊ณ ์ฆ์ ๋ฌธ๊ฐ์ผ ๋๋ง)
|
492 |
+
if role == "๊ณ ์ฆ์ ๋ฌธ๊ฐ" and self.web_searcher.enabled:
|
493 |
+
verification_results = self.web_searcher.verify_facts(act_content, act_name)
|
494 |
+
expert_output += f"\n\nใ์น ๊ฒ์ฆ ๊ฒฐ๊ณผใ\n{json.dumps(verification_results, ensure_ascii=False, indent=2)}"
|
495 |
+
|
496 |
+
# ํผ๋๋ฐฑ ์์ฑ
|
497 |
+
feedback = ExpertFeedback(
|
498 |
+
role=role,
|
499 |
+
stage=f"{act_name}_{stage_type}",
|
500 |
+
feedback=expert_output[:500],
|
501 |
+
suggestions=self._extract_suggestions(expert_output),
|
502 |
+
score=85.0 + random.uniform(-5, 10)
|
503 |
+
)
|
504 |
+
act_progress.expert_feedbacks.append(feedback)
|
505 |
+
|
506 |
+
# ์ต์ข
์์ฑ ๋จ๊ณ์์๋ง ์ฝํ
์ธ ์
๋ฐ์ดํธ
|
507 |
+
if stage_type == "์์ฑ":
|
508 |
+
act_content = expert_output
|
509 |
+
act_progress.content = act_content
|
510 |
+
elif stage_type == "์ด๊ณ ":
|
511 |
+
act_content = expert_output
|
512 |
+
|
513 |
+
# DB ์ ์ฅ
|
514 |
+
ScreenplayDatabase.save_act_progress(
|
515 |
+
session_id, act_name, idx+1, role,
|
516 |
+
expert_output[:1000], feedback.feedback, feedback.score
|
517 |
+
)
|
518 |
+
|
519 |
+
# ์งํ๋ฅ ํ์
|
520 |
+
progress_msg = f"โ
{role} ์์
์๋ฃ ({act_progress.current_stage}/{act_progress.total_stages})"
|
521 |
+
yield act_progress, progress_msg
|
522 |
+
|
523 |
+
time.sleep(0.5) # API ์ ํ ๊ณ ๋ ค
|
524 |
+
|
525 |
+
# ๋ง ์์ฑ
|
526 |
+
act_progress.status = "complete"
|
527 |
+
ScreenplayDatabase.save_act_content(session_id, act_name, act_content)
|
528 |
+
|
529 |
+
yield act_progress, f"โ
{act_name} ์์ฑ!"
|
530 |
+
|
531 |
+
def _create_writer_prompt(self, act_name: str, planning_data: Dict,
|
532 |
+
previous_acts: Dict, stage_type: str) -> str:
|
533 |
+
"""์คํ ๋ฆฌ ์๊ฐ ํ๋กฌํํธ"""
|
534 |
+
|
535 |
+
target_lines = 1000 if stage_type == "์ด๊ณ " else 1200
|
536 |
+
|
537 |
+
previous_content = ""
|
538 |
+
if previous_acts:
|
539 |
+
for act, content in previous_acts.items():
|
540 |
+
if content:
|
541 |
+
previous_content += f"\nใ{act}ใ\n{content[:500]}...\n"
|
542 |
+
|
543 |
+
return f"""ใ{act_name} {stage_type} ์์ฑใ
|
544 |
+
|
545 |
+
์๋ณธ ์์ฒญ: {self.original_query}
|
546 |
+
|
547 |
+
๋ชฉํ ๋ถ๋: {target_lines}์ค ์ด์
|
548 |
+
|
549 |
+
ใ๊ธฐํ์ใ
|
550 |
+
{self._summarize_planning(planning_data)}
|
551 |
+
|
552 |
+
ใ์ด์ ๋ง ๋ด์ฉใ
|
553 |
+
{previous_content if previous_content else "์ฒซ ๋ง์
๋๋ค"}
|
554 |
+
|
555 |
+
ใ์์ฑ ์๊ตฌ์ฌํญใ
|
556 |
+
1. ํ์ค ์๋๋ฆฌ์ค ํฌ๋งท
|
557 |
+
- INT./EXT. ์ฅ์ - ์๊ฐ
|
558 |
+
- ์บ๋ฆญํฐ๋ช
(๋๋ฌธ์)
|
559 |
+
- ๋์ฌ์ ์ก์
๊ตฌ๋ถ
|
560 |
+
|
561 |
+
2. ์ถฉ๋ถํ ๋ถ๋
|
562 |
+
- ๊ฐ ์ฌ 5-7ํ์ด์ง
|
563 |
+
- ์์ธํ ์ก์
๋ฌ์ฌ
|
564 |
+
- ์์ฐ์ค๋ฌ์ด ๋ํ
|
565 |
+
|
566 |
+
3. ์์ ์ถฉ์ค
|
567 |
+
- ๊ธฐํ์ ๋ด์ฉ ์ค์
|
568 |
+
- ์บ๋ฆญํฐ ์ผ๊ด์ฑ
|
569 |
+
- ์คํ ๋ฆฌ ์ฐ์์ฑ
|
570 |
+
|
571 |
+
๋ฐ๋์ {target_lines}์ค ์ด์ ์์ฑํ์ธ์."""
|
572 |
+
|
573 |
+
def _create_verification_prompt(self, act_name: str, content: str) -> str:
|
574 |
+
"""๊ณ ์ฆ ์ ๋ฌธ๊ฐ ํ๋กฌํํธ"""
|
575 |
+
return f"""ใ{act_name} ์ฌ์ค ํ์ธ ๋ฐ ๊ณ ์ฆใ
|
576 |
+
|
577 |
+
๊ฒํ ํ ๋ด์ฉ:
|
578 |
+
{content[:2000]}...
|
579 |
+
|
580 |
+
ใ๊ฒ์ฆ ํญ๋ชฉใ
|
581 |
+
1. ์ญ์ฌ์ ์ ํ์ฑ
|
582 |
+
- ์๋ ๋ฐฐ๊ฒฝ ์ ์ ์ฑ
|
583 |
+
- ์ฌ๊ฑด/์ธ๋ฌผ ์ฌ์ค ํ์ธ
|
584 |
+
|
585 |
+
2. ๊ณผํ์ ํ๋น์ฑ
|
586 |
+
- ๊ธฐ์ ์ ๋ฌ์ฌ ์ ํ์ฑ
|
587 |
+
- ๋ฌผ๋ฆฌ ๋ฒ์น ์ค์
|
588 |
+
|
589 |
+
3. ๋ฌธํ์ ์ ์ ์ฑ
|
590 |
+
- ์ธ์ด ์ฌ์ฉ
|
591 |
+
- ๊ด์ต๊ณผ ์์
|
592 |
+
|
593 |
+
4. ํ์ค์ฑ
|
594 |
+
- ํ๋์ ๊ฐ์ฐ์ฑ
|
595 |
+
- ์ํฉ์ ํ๋น์ฑ
|
596 |
+
|
597 |
+
ใ์์ ํ์ ์ฌํญใ
|
598 |
+
๊ตฌ์ฒด์ ์ธ ์ค๋ฅ์ ์์ ์์ ์ ์ํ์ธ์."""
|
599 |
+
|
600 |
+
def _create_editor_prompt(self, act_name: str, content: str) -> str:
|
601 |
+
"""ํธ์ง์ ํ๋กฌํํธ"""
|
602 |
+
return f"""ใ{act_name} ํธ์ง ๋ฐ ๊ตฌ์กฐ ์กฐ์ ใ
|
603 |
+
|
604 |
+
ํ์ฌ ๋ด์ฉ:
|
605 |
+
{content[:2000]}...
|
606 |
+
|
607 |
+
ใํธ์ง ํฌ์ธํธใ
|
608 |
+
1. ํ์ด์ฑ ์ต์ ํ
|
609 |
+
- ์ฌ ๊ธธ์ด ์กฐ์
|
610 |
+
- ๊ธด์ฅ/์ด์ ๋ฆฌ๋ฌ
|
611 |
+
|
612 |
+
2. ๊ตฌ์กฐ ๊ฐ์
|
613 |
+
- ์ฌ ์์ ์ต์ ํ
|
614 |
+
- ์ ํ ์์ฐ์ค๋ฌ์
|
615 |
+
|
616 |
+
3. ํธ๋ฆฌ๋ฐ
|
617 |
+
- ๋ถํ์ํ ๋ถ๋ถ ์ ๊ฑฐ
|
618 |
+
- ์ค๋ณต ์ ๊ฑฐ
|
619 |
+
|
620 |
+
4. ์ํฉํธ ๊ฐํ
|
621 |
+
- ํต์ฌ ์ฅ๋ฉด ๊ฐ์กฐ
|
622 |
+
- ๊ฐ์ ์ ๋นํธ
|
623 |
+
|
624 |
+
ํธ์ง๋ ๋ฒ์ ์ ์ ์ํ์ธ์."""
|
625 |
+
|
626 |
+
def _create_director_prompt(self, act_name: str, content: str) -> str:
|
627 |
+
"""๊ฐ๋
ํ๋กฌํํธ"""
|
628 |
+
return f"""ใ{act_name} ๋น์ฃผ์ผ ์ฐ์ถใ
|
629 |
+
|
630 |
+
์๋๋ฆฌ์ค ๊ฒํ :
|
631 |
+
{content[:2000]}...
|
632 |
+
|
633 |
+
ใ์ฐ์ถ ๊ฐํใ
|
634 |
+
1. ์คํ๋ ๋น์ฃผ์ผ
|
635 |
+
- ์ฒซ ์ด๋ฏธ์ง
|
636 |
+
- ํค ์ค์
|
637 |
+
|
638 |
+
2. ํต์ฌ ์ฌ ์ฐ์ถ
|
639 |
+
- ์นด๋ฉ๋ผ ์ต๊ธ
|
640 |
+
- ์์ง์
|
641 |
+
- ์กฐ๋ช
|
642 |
+
|
643 |
+
3. ๊ฐ์ ํํ
|
644 |
+
- ํด๋ก์ฆ์
|
645 |
+
- ๋ฆฌ์ก์
์ท
|
646 |
+
|
647 |
+
4. ์ ํ ์ฐ์ถ
|
648 |
+
- ์ฌ ์ฐ๊ฒฐ
|
649 |
+
- ์๊ฐ/๊ณต๊ฐ ์ด๋
|
650 |
+
|
651 |
+
๋น์ฃผ์ผ ๋
ธํธ๋ฅผ ์ถ๊ฐํ์ธ์."""
|
652 |
+
|
653 |
+
def _create_dialogue_prompt(self, act_name: str, content: str) -> str:
|
654 |
+
"""๋ํ ์ ๋ฌธ๊ฐ ํ๋กฌํํธ"""
|
655 |
+
return f"""ใ{act_name} ๋์ฌ ๊ฐ์ ใ
|
656 |
+
|
657 |
+
ํ์ฌ ๋์ฌ:
|
658 |
+
{content[:2000]}...
|
659 |
+
|
660 |
+
ใ๊ฐ์ ๋ฐฉํฅใ
|
661 |
+
1. ์บ๋ฆญํฐ ๋ณด์ด์ค
|
662 |
+
- ๊ณ ์ ํ ๋งํฌ
|
663 |
+
- ์ดํ ์์ค
|
664 |
+
|
665 |
+
2. ์๋ธํ
์คํธ
|
666 |
+
- ์จ์ ์๋ฏธ
|
667 |
+
- ๊ฐ์ ๋ ์ด์ด
|
668 |
+
|
669 |
+
3. ์์ฐ์ค๋ฌ์
|
670 |
+
- ์ผ์ ๋ํ
|
671 |
+
- ๋ฆฌ๋ฌ๊ณผ ํ
ํฌ
|
672 |
+
|
673 |
+
4. ํต์ฌ ๋์ฌ
|
674 |
+
- ๋ช
๋์ฌ
|
675 |
+
- ํ
๋ง ์ ๋ฌ
|
676 |
+
|
677 |
+
๊ฐ์ ๋ ๋์ฌ๋ฅผ ์ ์ํ์ธ์."""
|
678 |
+
|
679 |
+
def _create_critic_prompt(self, act_name: str, content: str) -> str:
|
680 |
+
"""๋นํ๊ฐ ํ๋กฌํํธ"""
|
681 |
+
return f"""ใ{act_name} ์ข
ํฉ ํ๊ฐใ
|
682 |
+
|
683 |
+
ํ๊ฐ ๋์:
|
684 |
+
{content[:2000]}...
|
685 |
+
|
686 |
+
ใํ๊ฐ ํญ๋ชฉใ
|
687 |
+
1. ์คํ ๋ฆฌ (30์ )
|
688 |
+
- ๋
ผ๋ฆฌ์ฑ
|
689 |
+
- ํ๋ฆ
|
690 |
+
- ๊ธด์ฅ๊ฐ
|
691 |
+
|
692 |
+
2. ์บ๋ฆญํฐ (30์ )
|
693 |
+
- ์ผ๊ด์ฑ
|
694 |
+
- ๋งค๋ ฅ๋
|
695 |
+
- ์ฑ์ฅ
|
696 |
+
|
697 |
+
3. ๋์ฌ (20์ )
|
698 |
+
- ์์ฐ์ค๋ฌ์
|
699 |
+
- ๊ฐ์ฑ
|
700 |
+
|
701 |
+
4. ์์ฑ๋ (20์ )
|
702 |
+
- ํฌ๋งท
|
703 |
+
- ๊ฐ๋
์ฑ
|
704 |
+
|
705 |
+
์ด์ : /100
|
706 |
+
|
707 |
+
๊ฐ์ ์ ์์ ํ์ธ์."""
|
708 |
+
|
709 |
+
def _summarize_planning(self, planning_data: Dict) -> str:
|
710 |
+
"""๊ธฐํ์ ์์ฝ"""
|
711 |
+
summary = ""
|
712 |
+
for key, value in planning_data.items():
|
713 |
+
if value:
|
714 |
+
summary += f"[{key}]\n{value[:300]}...\n\n"
|
715 |
+
return summary[:1500]
|
716 |
+
|
717 |
+
def _extract_suggestions(self, content: str) -> List[str]:
|
718 |
+
"""์ ์ ์ฌํญ ์ถ์ถ"""
|
719 |
+
suggestions = []
|
720 |
+
lines = content.split('\n')
|
721 |
+
for line in lines:
|
722 |
+
if any(k in line for k in ['๊ฐ์ ', '์ ์', '์์ ', '์ถ์ฒ']):
|
723 |
+
suggestions.append(line.strip())
|
724 |
+
return suggestions[:5]
|
725 |
+
|
726 |
+
# UI ์
๋ฐ์ดํธ ํจ์
|
727 |
+
def create_act_progress_display(act_progress: ActProgress) -> str:
|
728 |
+
"""๋ง๋ณ ์งํ ์ํฉ ํ์"""
|
729 |
+
if not act_progress:
|
730 |
+
return ""
|
731 |
+
|
732 |
+
html = f"""
|
733 |
+
<div style="border: 2px solid #667eea; border-radius: 10px; padding: 15px; margin: 10px 0;">
|
734 |
+
<h3>{act_progress.act_name} ์งํ ์ํฉ</h3>
|
735 |
+
|
736 |
+
<div style="margin: 10px 0;">
|
737 |
+
<div style="background: #e0e0e0; border-radius: 10px; height: 30px; position: relative;">
|
738 |
+
<div style="background: linear-gradient(90deg, #667eea, #764ba2);
|
739 |
+
height: 100%; border-radius: 10px; width: {act_progress.progress_percentage}%;
|
740 |
+
transition: width 0.3s ease;">
|
741 |
+
<span style="position: absolute; left: 50%; transform: translateX(-50%);
|
742 |
+
color: white; line-height: 30px; font-weight: bold;">
|
743 |
+
{act_progress.progress_percentage:.0f}%
|
744 |
+
</span>
|
745 |
+
</div>
|
746 |
+
</div>
|
747 |
+
</div>
|
748 |
+
|
749 |
+
<div style="margin-top: 15px;">
|
750 |
+
<strong>ํ์ฌ ์์
:</strong> {EXPERT_ROLES[act_progress.current_expert]['emoji']} {act_progress.current_expert}
|
751 |
+
<br>
|
752 |
+
<strong>๋จ๊ณ:</strong> {act_progress.current_stage} / {act_progress.total_stages}
|
753 |
+
<br>
|
754 |
+
<strong>์ํ:</strong> {act_progress.status}
|
755 |
+
</div>
|
756 |
+
</div>
|
757 |
+
"""
|
758 |
+
|
759 |
+
# ์ ๋ฌธ๊ฐ ํผ๋๋ฐฑ ํ์
|
760 |
+
if act_progress.expert_feedbacks:
|
761 |
+
html += """
|
762 |
+
<div style="background: #f8f9fa; border-radius: 8px; padding: 10px; margin-top: 10px;">
|
763 |
+
<h4>์ ๋ฌธ๊ฐ ์์
ํํฉ</h4>
|
764 |
+
"""
|
765 |
+
|
766 |
+
for fb in act_progress.expert_feedbacks:
|
767 |
+
emoji = EXPERT_ROLES[fb.role]['emoji']
|
768 |
+
html += f"""
|
769 |
+
<div style="border-left: 3px solid #667eea; padding-left: 10px; margin: 5px 0;">
|
770 |
+
<strong>{emoji} {fb.role}</strong> - ์ ์: {fb.score:.1f}/100<br>
|
771 |
+
<small>{fb.feedback[:100]}...</small>
|
772 |
+
</div>
|
773 |
+
"""
|
774 |
+
|
775 |
+
html += "</div>"
|
776 |
+
|
777 |
+
return html
|
778 |
+
|
779 |
+
def format_screenplay_display(screenplay_text: str) -> str:
|
780 |
+
"""์๋๋ฆฌ์ค ํ์ ํฌ๋งท"""
|
781 |
+
if not screenplay_text:
|
782 |
+
return "์๋๋ฆฌ์ค๊ฐ ์์ง ์์ฑ๋์ง ์์์ต๋๋ค."
|
783 |
+
|
784 |
+
formatted = "# ๐ฌ ์๋๋ฆฌ์ค\n\n"
|
785 |
+
|
786 |
+
# ์ฌ ํค๋ฉ ๊ฐ์กฐ
|
787 |
+
formatted_text = re.sub(
|
788 |
+
r'^(INT\.|EXT\.).*$',
|
789 |
+
r'**\g<0>**',
|
790 |
+
screenplay_text,
|
791 |
+
flags=re.MULTILINE
|
792 |
+
)
|
793 |
+
|
794 |
+
# ์บ๋ฆญํฐ๋ช
๊ฐ์กฐ
|
795 |
+
formatted_text = re.sub(
|
796 |
+
r'^([๊ฐ-ํฃA-Z][๊ฐ-ํฃA-Z\s]+)$',
|
797 |
+
r'**\g<0>**',
|
798 |
+
formatted_text,
|
799 |
+
flags=re.MULTILINE
|
800 |
+
)
|
801 |
+
|
802 |
+
# ํ์ด์ง ์ ๊ณ์ฐ
|
803 |
+
page_count = len(screenplay_text.splitlines()) / 58
|
804 |
+
formatted = f"**์ด ํ์ด์ง: {page_count:.1f}**\n\n" + formatted_text
|
805 |
+
|
806 |
+
return formatted
|
807 |
+
|
808 |
+
# Gradio ์ธํฐํ์ด์ค
|
809 |
+
def create_interface():
|
810 |
+
css = """
|
811 |
+
.main-header {
|
812 |
+
text-align: center;
|
813 |
+
margin-bottom: 2rem;
|
814 |
+
padding: 2.5rem;
|
815 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
816 |
+
border-radius: 15px;
|
817 |
+
color: white;
|
818 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
819 |
+
}
|
820 |
+
|
821 |
+
.expert-card {
|
822 |
+
background: white;
|
823 |
+
border: 1px solid #e0e0e0;
|
824 |
+
border-radius: 8px;
|
825 |
+
padding: 10px;
|
826 |
+
margin: 5px;
|
827 |
+
display: inline-block;
|
828 |
+
}
|
829 |
+
|
830 |
+
.act-button {
|
831 |
+
min-height: 60px;
|
832 |
+
font-size: 1.1rem;
|
833 |
+
margin: 5px;
|
834 |
+
}
|
835 |
+
|
836 |
+
.progress-container {
|
837 |
+
background: #f8f9fa;
|
838 |
+
border-radius: 10px;
|
839 |
+
padding: 20px;
|
840 |
+
margin: 15px 0;
|
841 |
+
}
|
842 |
+
"""
|
843 |
+
|
844 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=css, title="AI ์๋๋ฆฌ์ค ์๊ฐ") as interface:
|
845 |
+
gr.HTML("""
|
846 |
+
<div class="main-header">
|
847 |
+
<h1 style="font-size: 3rem;">๐ฌ AI ์๋๋ฆฌ์ค ์๊ฐ</h1>
|
848 |
+
<p style="font-size: 1.2rem;">
|
849 |
+
์ ๋ฌธ๊ฐ ํ์
์์คํ
์ผ๋ก ์๋ฒฝํ ์๋๋ฆฌ์ค๋ฅผ ์์ฑํฉ๋๋ค<br>
|
850 |
+
๋ง๋ณ๋ก ๋จ๊ณ์ ์ผ๋ก ์งํํ๋ฉฐ, ์น ๊ฒ์์ ํตํ ๊ณ ์ฆ๊น์ง ์ํํฉ๋๋ค
|
851 |
+
</p>
|
852 |
+
</div>
|
853 |
+
""")
|
854 |
+
|
855 |
+
# ์ํ ๋ณ์
|
856 |
+
current_session_id = gr.State(None)
|
857 |
+
current_planning = gr.State({})
|
858 |
+
act1_content = gr.State("")
|
859 |
+
act2a_content = gr.State("")
|
860 |
+
act2b_content = gr.State("")
|
861 |
+
act3_content = gr.State("")
|
862 |
+
|
863 |
+
with gr.Tabs():
|
864 |
+
with gr.Tab("๐ ์๋๋ฆฌ์ค ์์ฑ"):
|
865 |
+
# ๊ธฐ๋ณธ ์
๋ ฅ
|
866 |
+
with gr.Row():
|
867 |
+
with gr.Column(scale=2):
|
868 |
+
query_input = gr.Textbox(
|
869 |
+
label="๐ก ์๋๋ฆฌ์ค ์์ด๋์ด",
|
870 |
+
placeholder="๊ตฌ์ฒด์ ์ธ ์คํ ๋ฆฌ ์์ด๋์ด๋ฅผ ์
๋ ฅํ์ธ์...",
|
871 |
+
lines=4
|
872 |
+
)
|
873 |
+
|
874 |
+
with gr.Column(scale=1):
|
875 |
+
screenplay_type = gr.Radio(
|
876 |
+
choices=list(SCREENPLAY_LENGTHS.keys()),
|
877 |
+
value="์ํ",
|
878 |
+
label="์ ํ"
|
879 |
+
)
|
880 |
+
genre_select = gr.Dropdown(
|
881 |
+
choices=["์ก์
", "์ค๋ฆด๋ฌ", "๋๋ผ๋ง", "์ฝ๋ฏธ๋", "๊ณตํฌ", "SF", "๋ก๋งจ์ค", "ํํ์ง"],
|
882 |
+
value="๋๋ผ๋ง",
|
883 |
+
label="์ฅ๋ฅด"
|
884 |
+
)
|
885 |
+
|
886 |
+
planning_btn = gr.Button("๐ ๊ธฐํ์ ์์ฑ", variant="primary", size="lg")
|
887 |
+
|
888 |
+
# ๊ธฐํ์ ํ์
|
889 |
+
planning_display = gr.Markdown("*๊ธฐํ์์ด ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค...*")
|
890 |
+
|
891 |
+
# ๋ง๋ณ ์์ฑ ๋ฒํผ๋ค
|
892 |
+
gr.Markdown("### ๐ญ ๋ง๋ณ ์๋๋ฆฌ์ค ์์ฑ")
|
893 |
+
gr.Markdown("๊ฐ ๋ง์ ์์ฐจ์ ์ผ๋ก ์์ฑํ์ธ์. ๊ฐ ๋ง๋ง๋ค 7๋ช
์ ์ ๋ฌธ๊ฐ๊ฐ ํ์
ํฉ๋๋ค.")
|
894 |
+
|
895 |
+
with gr.Row():
|
896 |
+
act1_btn = gr.Button(
|
897 |
+
"1๏ธโฃ 1๋ง ์์ฑ\n(์ค์ - 25%)",
|
898 |
+
variant="primary",
|
899 |
+
elem_classes=["act-button"]
|
900 |
+
)
|
901 |
+
act2a_btn = gr.Button(
|
902 |
+
"2๏ธโฃ 2๋งA ์์ฑ\n(์์น - 25%)",
|
903 |
+
variant="secondary",
|
904 |
+
elem_classes=["act-button"]
|
905 |
+
)
|
906 |
+
act2b_btn = gr.Button(
|
907 |
+
"3๏ธโฃ 2๋งB ์์ฑ\n(๋ณต์กํ - 25%)",
|
908 |
+
variant="secondary",
|
909 |
+
elem_classes=["act-button"]
|
910 |
+
)
|
911 |
+
act3_btn = gr.Button(
|
912 |
+
"4๏ธโฃ 3๋ง ์์ฑ\n(ํด๊ฒฐ - 25%)",
|
913 |
+
variant="secondary",
|
914 |
+
elem_classes=["act-button"]
|
915 |
+
)
|
916 |
+
|
917 |
+
# ์งํ ์ํฉ ํ์
|
918 |
+
gr.Markdown("### ๐ ์์ฑ ์งํ ์ํฉ")
|
919 |
+
progress_display = gr.HTML(
|
920 |
+
value='<div class="progress-container">๋๊ธฐ ์ค...</div>'
|
921 |
+
)
|
922 |
+
status_text = gr.Textbox(
|
923 |
+
label="ํ์ฌ ์ํ",
|
924 |
+
value="๊ธฐํ์์ ๋จผ์ ์์ฑํด์ฃผ์ธ์",
|
925 |
+
interactive=False
|
926 |
+
)
|
927 |
+
|
928 |
+
# ์ ๋ฌธ๊ฐ ์์
ํํฉ
|
929 |
+
gr.Markdown("### ๐ฅ ์ ๋ฌธ๊ฐ ์์
ํํฉ")
|
930 |
+
expert_status = gr.HTML("""
|
931 |
+
<div style="padding: 10px;">
|
932 |
+
<span class="expert-card">๐ฌ ํ๋ก๋์</span>
|
933 |
+
<span class="expert-card">๐ ์คํ ๋ฆฌ์๊ฐ</span>
|
934 |
+
<span class="expert-card">๐ ๊ณ ์ฆ์ ๋ฌธ๊ฐ</span>
|
935 |
+
<span class="expert-card">โ๏ธ ํธ์ง์</span>
|
936 |
+
<span class="expert-card">๐ญ ๊ฐ๋
</span>
|
937 |
+
<span class="expert-card">๐ฌ ๋ํ์ ๋ฌธ๊ฐ</span>
|
938 |
+
<span class="expert-card">๐ ๋นํ๊ฐ</span>
|
939 |
+
</div>
|
940 |
+
""")
|
941 |
+
|
942 |
+
# ์๋๋ฆฌ์ค ์ถ๋ ฅ
|
943 |
+
gr.Markdown("### ๐ ์์ฑ๋ ์๋๋ฆฌ์ค")
|
944 |
+
with gr.Tabs():
|
945 |
+
with gr.Tab("1๋ง"):
|
946 |
+
act1_output = gr.Markdown("*1๋ง์ด ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค...*")
|
947 |
+
with gr.Tab("2๋งA"):
|
948 |
+
act2a_output = gr.Markdown("*2๋งA๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค...*")
|
949 |
+
with gr.Tab("2๋งB"):
|
950 |
+
act2b_output = gr.Markdown("*2๋งB๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค...*")
|
951 |
+
with gr.Tab("3๋ง"):
|
952 |
+
act3_output = gr.Markdown("*3๋ง์ด ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค...*")
|
953 |
+
with gr.Tab("์ ์ฒด"):
|
954 |
+
full_output = gr.Markdown("*์ ์ฒด ์๋๋ฆฌ์ค๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค...*")
|
955 |
+
|
956 |
+
download_btn = gr.Button("๐พ ์ ์ฒด ์๋๋ฆฌ์ค ๋ค์ด๋ก๋")
|
957 |
+
|
958 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
959 |
+
def handle_planning(query, s_type, genre):
|
960 |
+
if not query:
|
961 |
+
return "โ ์์ด๋์ด๋ฅผ ์
๋ ฅํด์ฃผ์ธ์", {}, None
|
962 |
+
|
963 |
+
# ๊ฐ๋จํ ๊ธฐํ์ ์์ฑ (์ค์ ๋ก๋ ๋ ๋ณต์กํ ๋ก์ง)
|
964 |
+
planning = {
|
965 |
+
"์ ๋ชฉ": "๋ฌด์ ",
|
966 |
+
"๋ก๊ทธ๋ผ์ธ": query[:100],
|
967 |
+
"์ฅ๋ฅด": genre,
|
968 |
+
"ํ์": s_type,
|
969 |
+
"์๋์์ค": query
|
970 |
+
}
|
971 |
+
|
972 |
+
session_id = ScreenplayDatabase.create_session(query, s_type, genre)
|
973 |
+
|
974 |
+
planning_text = f"""## ๐ ์๋๋ฆฌ์ค ๊ธฐํ์
|
975 |
+
|
976 |
+
**์ ๋ชฉ:** {planning['์ ๋ชฉ']}
|
977 |
+
**์ฅ๋ฅด:** {planning['์ฅ๋ฅด']}
|
978 |
+
**ํ์:** {planning['ํ์']}
|
979 |
+
|
980 |
+
**๋ก๊ทธ๋ผ์ธ:**
|
981 |
+
{planning['๋ก๊ทธ๋ผ์ธ']}
|
982 |
+
|
983 |
+
**์๋์์ค:**
|
984 |
+
{planning['์๋์์ค']}
|
985 |
+
|
986 |
+
---
|
987 |
+
โ
๊ธฐํ์์ด ์์ฑ๋์์ต๋๋ค. ์ด์ ๋ง๋ณ๋ก ์๋๋ฆฌ์ค๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.
|
988 |
+
"""
|
989 |
+
|
990 |
+
return planning_text, planning, session_id
|
991 |
+
|
992 |
+
def handle_act_writing(act_name, session_id, planning_data, previous_acts):
|
993 |
+
if not session_id:
|
994 |
+
yield "", "โ ๋จผ์ ๊ธฐํ์์ ์์ฑํด์ฃผ์ธ์", ""
|
995 |
+
return
|
996 |
+
|
997 |
+
system = ScreenplayGenerationSystem()
|
998 |
+
|
999 |
+
for act_progress, status_msg in system.generate_act(
|
1000 |
+
session_id, act_name, planning_data, previous_acts
|
1001 |
+
):
|
1002 |
+
progress_html = create_act_progress_display(act_progress)
|
1003 |
+
screenplay_display = format_screenplay_display(act_progress.content)
|
1004 |
+
|
1005 |
+
yield progress_html, status_msg, screenplay_display
|
1006 |
+
|
1007 |
+
# ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
1008 |
+
planning_btn.click(
|
1009 |
+
fn=handle_planning,
|
1010 |
+
inputs=[query_input, screenplay_type, genre_select],
|
1011 |
+
outputs=[planning_display, current_planning, current_session_id]
|
1012 |
+
)
|
1013 |
+
|
1014 |
+
act1_btn.click(
|
1015 |
+
fn=lambda sid, plan: handle_act_writing("1๋ง", sid, plan, {}),
|
1016 |
+
inputs=[current_session_id, current_planning],
|
1017 |
+
outputs=[progress_display, status_text, act1_output]
|
1018 |
+
).then(
|
1019 |
+
lambda x: x,
|
1020 |
+
inputs=[act1_output],
|
1021 |
+
outputs=[act1_content]
|
1022 |
+
)
|
1023 |
+
|
1024 |
+
act2a_btn.click(
|
1025 |
+
fn=lambda sid, plan, act1: handle_act_writing("2๋งA", sid, plan, {"1๋ง": act1}),
|
1026 |
+
inputs=[current_session_id, current_planning, act1_content],
|
1027 |
+
outputs=[progress_display, status_text, act2a_output]
|
1028 |
+
).then(
|
1029 |
+
lambda x: x,
|
1030 |
+
inputs=[act2a_output],
|
1031 |
+
outputs=[act2a_content]
|
1032 |
+
)
|
1033 |
+
|
1034 |
+
act2b_btn.click(
|
1035 |
+
fn=lambda sid, plan, act1, act2a: handle_act_writing(
|
1036 |
+
"2๋งB", sid, plan, {"1๋ง": act1, "2๋งA": act2a}
|
1037 |
+
),
|
1038 |
+
inputs=[current_session_id, current_planning, act1_content, act2a_content],
|
1039 |
+
outputs=[progress_display, status_text, act2b_output]
|
1040 |
+
).then(
|
1041 |
+
lambda x: x,
|
1042 |
+
inputs=[act2b_output],
|
1043 |
+
outputs=[act2b_content]
|
1044 |
+
)
|
1045 |
+
|
1046 |
+
act3_btn.click(
|
1047 |
+
fn=lambda sid, plan, act1, act2a, act2b: handle_act_writing(
|
1048 |
+
"3๋ง", sid, plan, {"1๋ง": act1, "2๋งA": act2a, "2๋งB": act2b}
|
1049 |
+
),
|
1050 |
+
inputs=[current_session_id, current_planning, act1_content, act2a_content, act2b_content],
|
1051 |
+
outputs=[progress_display, status_text, act3_output]
|
1052 |
+
).then(
|
1053 |
+
lambda x: x,
|
1054 |
+
inputs=[act3_output],
|
1055 |
+
outputs=[act3_content]
|
1056 |
+
)
|
1057 |
+
|
1058 |
+
# ์ ์ฒด ์๋๋ฆฌ์ค ํฉ์น๊ธฐ
|
1059 |
+
def combine_acts(act1, act2a, act2b, act3):
|
1060 |
+
full = "# ๐ฌ ์ ์ฒด ์๋๋ฆฌ์ค\n\n"
|
1061 |
+
if act1:
|
1062 |
+
full += f"## 1๋ง\n\n{act1}\n\n"
|
1063 |
+
if act2a:
|
1064 |
+
full += f"## 2๋งA\n\n{act2a}\n\n"
|
1065 |
+
if act2b:
|
1066 |
+
full += f"## 2๋งB\n\n{act2b}\n\n"
|
1067 |
+
if act3:
|
1068 |
+
full += f"## 3๋ง\n\n{act3}\n\n"
|
1069 |
+
return full
|
1070 |
+
|
1071 |
+
# ๋ง ์์ฑ ํ ์ ์ฒด ์
๋ฐ์ดํธ
|
1072 |
+
act3_btn.click(
|
1073 |
+
lambda a1, a2a, a2b, a3: combine_acts(a1, a2a, a2b, a3),
|
1074 |
+
inputs=[act1_content, act2a_content, act2b_content, act3_content],
|
1075 |
+
outputs=[full_output]
|
1076 |
+
)
|
1077 |
+
|
1078 |
+
return interface
|
1079 |
+
|
1080 |
+
# ๋ฉ์ธ ์คํ
|
1081 |
+
if __name__ == "__main__":
|
1082 |
+
logger.info("=" * 60)
|
1083 |
+
logger.info("AI ์๋๋ฆฌ์ค ์๊ฐ - ์ ๋ฌธ๊ฐ ํ์
์์คํ
")
|
1084 |
+
logger.info("๋ง๋ณ ๋จ๊ณ์ ์์ฑ + ์น ๊ฒ์ฆ ์์คํ
")
|
1085 |
+
logger.info("=" * 60)
|
1086 |
+
|
1087 |
+
if not FIREWORKS_API_KEY or FIREWORKS_API_KEY == "dummy_token_for_testing":
|
1088 |
+
logger.warning("โ ๏ธ FIREWORKS_API_KEY๋ฅผ ์ค์ ํด์ฃผ์ธ์!")
|
1089 |
+
|
1090 |
+
if BRAVE_SEARCH_API_KEY:
|
1091 |
+
logger.info("โ
์น ๊ฒ์ ๊ณ ์ฆ ๊ธฐ๋ฅ ํ์ฑํ")
|
1092 |
+
else:
|
1093 |
+
logger.warning("โ ๏ธ BRAVE_SEARCH_API_KEY ์์ - ์น ๊ฒ์ฆ ๋นํ์ฑํ")
|
1094 |
+
|
1095 |
+
ScreenplayDatabase.init_db()
|
1096 |
+
|
1097 |
+
interface = create_interface()
|
1098 |
+
interface.launch(
|
1099 |
+
server_name="0.0.0.0",
|
1100 |
+
server_port=7860,
|
1101 |
+
share=False
|
1102 |
+
)
|