Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2040,7 +2040,7 @@ def download_novel(novel_text: str, format: str, language: str, session_id: str
|
|
2040 |
if is_test_mode:
|
2041 |
# ํ
์คํธ ๋ชจ๋: writer1 revision + writer10 ๋ด์ฉ ์ฒ๋ฆฌ
|
2042 |
for stage in stages:
|
2043 |
-
logger.
|
2044 |
|
2045 |
# Writer 1 ์์ ๋ณธ
|
2046 |
if stage['role'] == 'writer1' and stage['stage_name'] and 'Revision' in stage['stage_name']:
|
@@ -2086,19 +2086,20 @@ def download_novel(novel_text: str, format: str, language: str, session_id: str
|
|
2086 |
logger.info(f"Added Chapter {chapter_num}: {word_count} words")
|
2087 |
else:
|
2088 |
# ์ผ๋ฐ ๋ชจ๋: ๋ชจ๋ ์๊ฐ ์์ ๋ณธ ์ฒ๋ฆฌ
|
|
|
|
|
2089 |
for stage in stages:
|
2090 |
-
logger.
|
2091 |
|
2092 |
if stage['role'] and stage['role'].startswith('writer') and stage['stage_name'] and 'Revision' in stage['stage_name']:
|
2093 |
# ์๊ฐ ๋ฒํธ ์ถ์ถ
|
2094 |
try:
|
2095 |
-
|
2096 |
-
logger.
|
2097 |
except:
|
2098 |
logger.warning(f"Could not extract writer number from role: {stage['role']}")
|
2099 |
continue
|
2100 |
-
|
2101 |
-
writer_count += 1
|
2102 |
content = stage['content'] or ""
|
2103 |
|
2104 |
# ํ์ด์ง ๋งํฌ ์ ๊ฑฐ
|
@@ -2110,11 +2111,17 @@ def download_novel(novel_text: str, format: str, language: str, session_id: str
|
|
2110 |
word_count = stage['word_count'] or len(content.split())
|
2111 |
total_words += word_count
|
2112 |
writer_contents.append({
|
2113 |
-
'writer_num':
|
2114 |
'content': content,
|
2115 |
'word_count': word_count
|
2116 |
})
|
2117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
2118 |
|
2119 |
# ํต๊ณ ํ์ด์ง
|
2120 |
doc.add_heading('Novel Statistics', 1)
|
@@ -2157,6 +2164,9 @@ def download_novel(novel_text: str, format: str, language: str, session_id: str
|
|
2157 |
|
2158 |
if idx < len(sorted_contents) - 1: # ๋ง์ง๋ง ์ฑํฐ ํ์๋ ํ์ด์ง ๊ตฌ๋ถ ์์
|
2159 |
doc.add_page_break()
|
|
|
|
|
|
|
2160 |
|
2161 |
# ํ์ด์ง ์ค์
|
2162 |
for section in doc.sections:
|
@@ -2178,7 +2188,7 @@ def download_novel(novel_text: str, format: str, language: str, session_id: str
|
|
2178 |
logger.info(f"DOCX saved successfully: {filepath} ({total_words} words, {writer_count} writers)")
|
2179 |
return filepath
|
2180 |
else:
|
2181 |
-
# TXT format
|
2182 |
temp_dir = tempfile.gettempdir()
|
2183 |
safe_filename = re.sub(r'[^\w\s-]', '', session['user_query'][:30]).strip()
|
2184 |
mode_suffix = "_TestMode" if is_test_mode else "_Complete"
|
@@ -2244,7 +2254,7 @@ def download_novel(novel_text: str, format: str, language: str, session_id: str
|
|
2244 |
f.write(chapter_content)
|
2245 |
f.write("\n\n")
|
2246 |
else:
|
2247 |
-
# ์ผ๋ฐ ๋ชจ๋
|
2248 |
for stage in stages:
|
2249 |
if stage['role'] and stage['role'].startswith('writer') and stage['stage_name'] and 'Revision' in stage['stage_name']:
|
2250 |
# ์๊ฐ ๋ฒํธ ์ถ์ถ
|
@@ -2252,8 +2262,7 @@ def download_novel(novel_text: str, format: str, language: str, session_id: str
|
|
2252 |
writer_num = int(stage['role'].replace('writer', ''))
|
2253 |
except:
|
2254 |
continue
|
2255 |
-
|
2256 |
-
writer_count += 1
|
2257 |
content = stage['content'] or ""
|
2258 |
# ํ์ด์ง ๋งํฌ ์ ๊ฑฐ
|
2259 |
content = re.sub(r'\[(?:ํ์ด์ง|Page|page)\s*\d+\]', '', content)
|
@@ -2263,9 +2272,10 @@ def download_novel(novel_text: str, format: str, language: str, session_id: str
|
|
2263 |
if content:
|
2264 |
word_count = stage['word_count'] or len(content.split())
|
2265 |
total_words += word_count
|
|
|
2266 |
|
2267 |
f.write(f"\n{'='*40}\n")
|
2268 |
-
f.write(f"CHAPTER {
|
2269 |
f.write(f"Word Count: {word_count:,}\n")
|
2270 |
f.write(f"{'='*40}\n\n")
|
2271 |
f.write(content)
|
|
|
2040 |
if is_test_mode:
|
2041 |
# ํ
์คํธ ๋ชจ๋: writer1 revision + writer10 ๋ด์ฉ ์ฒ๋ฆฌ
|
2042 |
for stage in stages:
|
2043 |
+
logger.info(f"[TEST MODE] Checking stage: role={stage['role']}, name={stage['stage_name']}, status={stage['status']}")
|
2044 |
|
2045 |
# Writer 1 ์์ ๋ณธ
|
2046 |
if stage['role'] == 'writer1' and stage['stage_name'] and 'Revision' in stage['stage_name']:
|
|
|
2086 |
logger.info(f"Added Chapter {chapter_num}: {word_count} words")
|
2087 |
else:
|
2088 |
# ์ผ๋ฐ ๋ชจ๋: ๋ชจ๋ ์๊ฐ ์์ ๋ณธ ์ฒ๋ฆฌ
|
2089 |
+
logger.info("[NORMAL MODE] Processing all writer revisions...")
|
2090 |
+
|
2091 |
for stage in stages:
|
2092 |
+
logger.info(f"[NORMAL MODE] Checking stage: role={stage['role']}, name={stage['stage_name']}, status={stage['status']}")
|
2093 |
|
2094 |
if stage['role'] and stage['role'].startswith('writer') and stage['stage_name'] and 'Revision' in stage['stage_name']:
|
2095 |
# ์๊ฐ ๋ฒํธ ์ถ์ถ
|
2096 |
try:
|
2097 |
+
writer_num = int(stage['role'].replace('writer', ''))
|
2098 |
+
logger.info(f"Found writer {writer_num} revision")
|
2099 |
except:
|
2100 |
logger.warning(f"Could not extract writer number from role: {stage['role']}")
|
2101 |
continue
|
2102 |
+
|
|
|
2103 |
content = stage['content'] or ""
|
2104 |
|
2105 |
# ํ์ด์ง ๋งํฌ ์ ๊ฑฐ
|
|
|
2111 |
word_count = stage['word_count'] or len(content.split())
|
2112 |
total_words += word_count
|
2113 |
writer_contents.append({
|
2114 |
+
'writer_num': writer_num, # โ
์ฌ๋ฐ๋ฅธ ์๊ฐ ๋ฒํธ ์ฌ์ฉ!
|
2115 |
'content': content,
|
2116 |
'word_count': word_count
|
2117 |
})
|
2118 |
+
writer_count += 1 # ์ค์ ์๊ฐ ์ ์นด์ดํธ
|
2119 |
+
logger.info(f"Added writer {writer_num}: {word_count} words, content length: {len(content)}")
|
2120 |
+
else:
|
2121 |
+
logger.warning(f"Writer {writer_num} has empty content after cleaning")
|
2122 |
+
|
2123 |
+
logger.info(f"Total writers collected: {writer_count}, Total words: {total_words}")
|
2124 |
+
logger.info(f"Writer contents: {len(writer_contents)} entries")
|
2125 |
|
2126 |
# ํต๊ณ ํ์ด์ง
|
2127 |
doc.add_heading('Novel Statistics', 1)
|
|
|
2164 |
|
2165 |
if idx < len(sorted_contents) - 1: # ๋ง์ง๋ง ์ฑํฐ ํ์๋ ํ์ด์ง ๊ตฌ๋ถ ์์
|
2166 |
doc.add_page_break()
|
2167 |
+
else:
|
2168 |
+
logger.warning("No writer contents found! Creating empty document.")
|
2169 |
+
doc.add_paragraph("No content found. Please check if the novel generation completed successfully.")
|
2170 |
|
2171 |
# ํ์ด์ง ์ค์
|
2172 |
for section in doc.sections:
|
|
|
2188 |
logger.info(f"DOCX saved successfully: {filepath} ({total_words} words, {writer_count} writers)")
|
2189 |
return filepath
|
2190 |
else:
|
2191 |
+
# TXT format - ๋์ผํ ์์ ์ ์ฉ
|
2192 |
temp_dir = tempfile.gettempdir()
|
2193 |
safe_filename = re.sub(r'[^\w\s-]', '', session['user_query'][:30]).strip()
|
2194 |
mode_suffix = "_TestMode" if is_test_mode else "_Complete"
|
|
|
2254 |
f.write(chapter_content)
|
2255 |
f.write("\n\n")
|
2256 |
else:
|
2257 |
+
# ์ผ๋ฐ ๋ชจ๋ - ์์ ๋ ๋ก์ง
|
2258 |
for stage in stages:
|
2259 |
if stage['role'] and stage['role'].startswith('writer') and stage['stage_name'] and 'Revision' in stage['stage_name']:
|
2260 |
# ์๊ฐ ๋ฒํธ ์ถ์ถ
|
|
|
2262 |
writer_num = int(stage['role'].replace('writer', ''))
|
2263 |
except:
|
2264 |
continue
|
2265 |
+
|
|
|
2266 |
content = stage['content'] or ""
|
2267 |
# ํ์ด์ง ๋งํฌ ์ ๊ฑฐ
|
2268 |
content = re.sub(r'\[(?:ํ์ด์ง|Page|page)\s*\d+\]', '', content)
|
|
|
2272 |
if content:
|
2273 |
word_count = stage['word_count'] or len(content.split())
|
2274 |
total_words += word_count
|
2275 |
+
writer_count += 1
|
2276 |
|
2277 |
f.write(f"\n{'='*40}\n")
|
2278 |
+
f.write(f"CHAPTER {writer_num} (Pages {(writer_num-1)*3+1}-{writer_num*3})\n")
|
2279 |
f.write(f"Word Count: {word_count:,}\n")
|
2280 |
f.write(f"{'='*40}\n\n")
|
2281 |
f.write(content)
|