Spaces:
Running
Running
Update content_utils.py
Browse files- content_utils.py +88 -0
content_utils.py
CHANGED
@@ -308,6 +308,94 @@ def parse_slide_section(section: str, default_title: str) -> Dict:
|
|
308 |
logger.error(f"์ฌ๋ผ์ด๋ ์น์
ํ์ฑ ์ค ์ค๋ฅ: {str(e)}")
|
309 |
return None
|
310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
def extract_speaker_notes_from_section(section: str) -> str:
|
312 |
"""์ฌ๋ผ์ด๋ ์น์
์์ ๋ฐํ์ ๋
ธํธ ์ถ์ถ"""
|
313 |
try:
|
|
|
308 |
logger.error(f"์ฌ๋ผ์ด๋ ์น์
ํ์ฑ ์ค ์ค๋ฅ: {str(e)}")
|
309 |
return None
|
310 |
|
311 |
+
def parse_slide_section_improved(section: str, default_title: str, slide_num: int) -> Dict:
|
312 |
+
"""์ฌ๋ผ์ด๋ ์น์
์์ ์ฝํ
์ธ ํ์ฑ - ์ฌ๋ผ์ด๋ 3 ๋ฌธ์ ํด๊ฒฐ"""
|
313 |
+
try:
|
314 |
+
content = {
|
315 |
+
"subtitle": default_title,
|
316 |
+
"bullet_points": []
|
317 |
+
}
|
318 |
+
|
319 |
+
# ๋ถ์ ๋ชฉ ์ถ์ถ (๋ ๋ง์ ํจํด)
|
320 |
+
subtitle_patterns = [
|
321 |
+
r'๋ถ์ ๋ชฉ:\s*(.+?)(?=\n|$)',
|
322 |
+
r'Subtitle:\s*(.+?)(?=\n|$)',
|
323 |
+
r'๋ถ์ :\s*(.+?)(?=\n|$)',
|
324 |
+
r'Sub:\s*(.+?)(?=\n|$)'
|
325 |
+
]
|
326 |
+
|
327 |
+
for pattern in subtitle_patterns:
|
328 |
+
match = re.search(pattern, section, re.MULTILINE)
|
329 |
+
if match:
|
330 |
+
subtitle = match.group(1).strip()
|
331 |
+
if subtitle and len(subtitle) > 2:
|
332 |
+
content["subtitle"] = subtitle
|
333 |
+
break
|
334 |
+
|
335 |
+
# ๋ถ๋ฆฟ ํฌ์ธํธ ์ถ์ถ - ๋ ์ ํํ ํจํด
|
336 |
+
# 1. ๋ช
์์ ์ธ "ํต์ฌ ๋ด์ฉ:" ์น์
์ฐพ๊ธฐ
|
337 |
+
content_section_match = re.search(
|
338 |
+
r'(?:ํต์ฌ\s*๋ด์ฉ|Key\s*Points|๋ด์ฉ):\s*\n(.+?)(?=๋ฐํ์|Speaker|์๊ฐ|Visual|$)',
|
339 |
+
section,
|
340 |
+
re.DOTALL | re.IGNORECASE
|
341 |
+
)
|
342 |
+
|
343 |
+
if content_section_match:
|
344 |
+
content_text = content_section_match.group(1)
|
345 |
+
lines = content_text.strip().split('\n')
|
346 |
+
|
347 |
+
for line in lines:
|
348 |
+
line = line.strip()
|
349 |
+
if not line:
|
350 |
+
continue
|
351 |
+
|
352 |
+
# ์ด๋ชจ์ง๋ก ์์ํ๋ ๋ผ์ธ
|
353 |
+
if len(line) > 0 and ord(line[0]) >= 0x1F300:
|
354 |
+
content["bullet_points"].append(line)
|
355 |
+
# ๋ถ๋ฆฟ์ผ๋ก ์์ํ๋ ๋ผ์ธ
|
356 |
+
elif line.startswith(('โข', '-', '*', 'ยท', 'โช', 'โธ')):
|
357 |
+
content["bullet_points"].append(line)
|
358 |
+
# ์๋ฏธ์๋ ๋ด์ฉ์ธ ๊ฒฝ์ฐ
|
359 |
+
elif len(line) > 10 and not any(skip in line for skip in [':', '์ ๋ชฉ', 'Title', '๋
ธํธ']):
|
360 |
+
# ์ซ์๋ก ์์ํ๋ฉด ์ ๊ฑฐ
|
361 |
+
clean_line = re.sub(r'^\d+[.)]\s*', '', line).strip()
|
362 |
+
if clean_line:
|
363 |
+
content["bullet_points"].append(f"โข {clean_line}")
|
364 |
+
|
365 |
+
# 2. ๋ถ๋ฆฟ ํฌ์ธํธ๊ฐ ๋ถ์กฑํ๋ฉด ์ ์ฒด ์น์
์์ ์ฐพ๊ธฐ
|
366 |
+
if len(content["bullet_points"]) < 3:
|
367 |
+
lines = section.split('\n')
|
368 |
+
for line in lines:
|
369 |
+
line = line.strip()
|
370 |
+
if not line or len(content["bullet_points"]) >= 5:
|
371 |
+
continue
|
372 |
+
|
373 |
+
# ๋ฉํ ์ ๋ณด ์คํต
|
374 |
+
if any(skip in line.lower() for skip in ['์ ๋ชฉ:', 'title:', '๋ถ์ ๋ชฉ:', 'subtitle:', '๋ฐํ์', 'speaker', '์๊ฐ']):
|
375 |
+
continue
|
376 |
+
|
377 |
+
# ์ด๋ชจ์ง๋ก ์์ํ๊ฑฐ๋ ๋ถ๋ฆฟ์ผ๋ก ์์
|
378 |
+
if (len(line) > 0 and ord(line[0]) >= 0x1F300) or line.startswith(('โข', '-', '*')):
|
379 |
+
if line not in content["bullet_points"]:
|
380 |
+
content["bullet_points"].append(line)
|
381 |
+
# ์ผ๋ฐ ํ
์คํธ์ง๋ง ์๋ฏธ์๋ ๋ด์ฉ
|
382 |
+
elif len(line) > 15 and ':' not in line:
|
383 |
+
formatted_line = f"โข {line}"
|
384 |
+
if formatted_line not in content["bullet_points"]:
|
385 |
+
content["bullet_points"].append(formatted_line)
|
386 |
+
|
387 |
+
# ์ค๋ณต ์ ๊ฑฐ
|
388 |
+
content["bullet_points"] = list(dict.fromkeys(content["bullet_points"]))[:5]
|
389 |
+
|
390 |
+
return content if len(content["bullet_points"]) > 0 else None
|
391 |
+
|
392 |
+
except Exception as e:
|
393 |
+
logger.error(f"์ฌ๋ผ์ด๋ {slide_num} ํ์ฑ ์ค ์ค๋ฅ: {str(e)}")
|
394 |
+
return None
|
395 |
+
|
396 |
+
|
397 |
+
|
398 |
+
|
399 |
def extract_speaker_notes_from_section(section: str) -> str:
|
400 |
"""์ฌ๋ผ์ด๋ ์น์
์์ ๋ฐํ์ ๋
ธํธ ์ถ์ถ"""
|
401 |
try:
|