openfree commited on
Commit
405dc84
ยท
verified ยท
1 Parent(s): 6f7ee57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +154 -48
app.py CHANGED
@@ -399,53 +399,18 @@ class ScreenplayDatabase:
399
  return session_id
400
 
401
  # In ScreenplayDatabase.save_stage method, add page count tracking
402
- @staticmethod
403
- def save_stage(session_id: str, stage_number: int, stage_name: str,
404
- role: str, content: str, status: str = 'complete'):
405
- page_count = 0
406
- if role == "screenwriter" and content:
407
- # Use the accurate page calculation
408
- system = ScreenplayGenerationSystem()
409
- page_count = system.calculate_screenplay_pages(content)
410
-
411
- with ScreenplayDatabase.get_db() as conn:
412
- cursor = conn.cursor()
413
- cursor.execute('''
414
- INSERT INTO screenplay_stages
415
- (session_id, stage_number, stage_name, role, content, page_count, status)
416
- VALUES (?, ?, ?, ?, ?, ?, ?)
417
- ON CONFLICT(session_id, stage_number)
418
- DO UPDATE SET content=?, page_count=?, status=?, updated_at=datetime('now')
419
- ''', (session_id, stage_number, stage_name, role, content, page_count, status,
420
- content, page_count, status))
421
-
422
- # Update total pages in session
423
- if role == "screenwriter" and "Expanded" in stage_name:
424
- cursor.execute('''
425
- UPDATE screenplay_sessions
426
- SET total_pages = (
427
- SELECT SUM(page_count)
428
- FROM screenplay_stages
429
- WHERE session_id = ?
430
- AND role = 'screenwriter'
431
- AND stage_name LIKE '%Expanded%'
432
- ),
433
- updated_at = datetime('now')
434
- WHERE session_id = ?
435
- ''', (session_id, session_id))
436
-
437
- conn.commit()# In ScreenplayDatabase.save_stage method, add page count tracking
438
-
439
-
440
  @staticmethod
441
  def save_stage(session_id: str, stage_number: int, stage_name: str,
442
  role: str, content: str, status: str = 'complete'):
443
  page_count = 0
 
 
444
  if role == "screenwriter" and content:
445
  # Use the accurate page calculation
446
- system = ScreenplayGenerationSystem()
447
  page_count = system.calculate_screenplay_pages(content)
448
 
 
449
  with ScreenplayDatabase.get_db() as conn:
450
  cursor = conn.cursor()
451
  cursor.execute('''
@@ -472,8 +437,9 @@ def save_stage(session_id: str, stage_number: int, stage_name: str,
472
  WHERE session_id = ?
473
  ''', (session_id, session_id))
474
 
475
- conn.commit()
476
 
 
477
 
478
 
479
  @staticmethod
@@ -1342,7 +1308,6 @@ Provide specific revision suggestions with improved examples."""
1342
 
1343
  return lang_prompts.get(language, lang_prompts["English"])
1344
 
1345
- # โญ ์—ฌ๊ธฐ์— ์ƒˆ๋กœ์šด ํ•จ์ˆ˜ ์ถ”๊ฐ€ (๊ธฐ์กด create_script_doctor_prompt ๋ฐ”๋กœ ์•„๋ž˜)
1346
  def create_script_doctor_expansion_prompt(self, act_content: str, act: str,
1347
  screenplay_type: str, genre: str,
1348
  language: str) -> str:
@@ -1355,13 +1320,89 @@ Provide specific revision suggestions with improved examples."""
1355
  expansion_needed = target_pages - current_pages
1356
 
1357
  lang_prompts = {
1358
- "Korean": f"""๋‹น์‹ ์€ ์Šคํฌ๋ฆฝํŠธ ๋‹ฅํ„ฐ์ž…๋‹ˆ๋‹ค...""",
1359
- "English": f"""You are a script doctor..."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1360
  }
1361
-
1362
  return lang_prompts.get(language, lang_prompts["English"])
1363
 
1364
- # โญ create_script_doctor_expansion_prompt ํ•จ์ˆ˜ ๋ฐ”๋กœ ์•„๋ž˜์— ์ถ”๊ฐ€
1365
  def create_expansion_writer_prompt(self, act: str, original_content: str,
1366
  expansion_notes: str, screenplay_type: str,
1367
  language: str) -> str:
@@ -1371,10 +1412,75 @@ Provide specific revision suggestions with improved examples."""
1371
  target_lines = target_pages * 55
1372
 
1373
  lang_prompts = {
1374
- "Korean": f"""์›๋ณธ {act}๋ฅผ ํ™•์žฅ ์ง€์‹œ์‚ฌํ•ญ์— ๋”ฐ๋ผ...""",
1375
- "English": f"""Rewrite {act} following expansion instructions..."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1376
  }
1377
-
1378
  return lang_prompts.get(language, lang_prompts["English"])
1379
 
1380
  def create_final_reviewer_prompt(self, complete_screenplay: str,
 
399
  return session_id
400
 
401
  # In ScreenplayDatabase.save_stage method, add page count tracking
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  @staticmethod
403
  def save_stage(session_id: str, stage_number: int, stage_name: str,
404
  role: str, content: str, status: str = 'complete'):
405
  page_count = 0
406
+
407
+ # save_stage ํ•จ์ˆ˜ ๋‚ด๋ถ€
408
  if role == "screenwriter" and content:
409
  # Use the accurate page calculation
410
+ system = ScreenplayGenerationSystem() # โŒ ๋งค๋ฒˆ ์ƒˆ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
411
  page_count = system.calculate_screenplay_pages(content)
412
 
413
+
414
  with ScreenplayDatabase.get_db() as conn:
415
  cursor = conn.cursor()
416
  cursor.execute('''
 
437
  WHERE session_id = ?
438
  ''', (session_id, session_id))
439
 
440
+ conn.commit()# In ScreenplayDatabase.save_stage method, add page count tracking
441
 
442
+
443
 
444
 
445
  @staticmethod
 
1308
 
1309
  return lang_prompts.get(language, lang_prompts["English"])
1310
 
 
1311
  def create_script_doctor_expansion_prompt(self, act_content: str, act: str,
1312
  screenplay_type: str, genre: str,
1313
  language: str) -> str:
 
1320
  expansion_needed = target_pages - current_pages
1321
 
1322
  lang_prompts = {
1323
+ "Korean": f"""๋‹น์‹ ์€ ์Šคํฌ๋ฆฝํŠธ ๋‹ฅํ„ฐ์ž…๋‹ˆ๋‹ค. {act}๋ฅผ ๊ฒ€ํ† ํ•˜๊ณ  ํ™•์žฅ ์ง€์‹œ์‚ฌํ•ญ์„ ์ œ๊ณตํ•˜์„ธ์š”.
1324
+
1325
+ **ํ˜„์žฌ ๋ถ„๋Ÿ‰:** {current_pages:.1f}ํŽ˜์ด์ง€ ({current_lines}์ค„)
1326
+ **๋ชฉํ‘œ ๋ถ„๋Ÿ‰:** {target_pages}ํŽ˜์ด์ง€
1327
+ **ํ•„์š” ์ถ”๊ฐ€๋ถ„:** {expansion_needed:.1f}ํŽ˜์ด์ง€ (์•ฝ {int(expansion_needed * 55)}์ค„)
1328
+
1329
+ **์ž‘์„ฑ๋œ ๋‚ด์šฉ:**
1330
+ {act_content}
1331
+
1332
+ **ํ™•์žฅ ๋ถ„์„ ๋ฐ ์ง€์‹œ์‚ฌํ•ญ:**
1333
+
1334
+ 1. **๋Œ€ํ™” ํ™•์žฅ ๊ธฐํšŒ**
1335
+ ๊ฐ ๋Œ€ํ™” ์‹œํ€€์Šค๋ฅผ ๊ฒ€ํ† ํ•˜๊ณ  ๋‹ค์Œ์„ ์ถ”๊ฐ€ํ•˜์„ธ์š”:
1336
+ - ๋น ๋ฅด๊ฒŒ ์ง„ํ–‰๋œ ๋Œ€ํ™”์— ์„œ๋ธŒํ…์ŠคํŠธ ์ถ”๊ฐ€
1337
+ - ๊ฐ์ •์  ๋น„ํŠธ์™€ ๋ฐ˜์‘ ์ถ”๊ฐ€
1338
+ - ๊ฐˆ๋“ฑ์„ ๋” ๊นŠ์ด ํƒ๊ตฌํ•  ๋Œ€ํ™”
1339
+ - ์บ๋ฆญํ„ฐ์˜ ๋‚ด๋ฉด์„ ๋“œ๋Ÿฌ๋‚ผ ๋Œ€์‚ฌ
1340
+
1341
+ 2. **์•ก์…˜/๋ฌ˜์‚ฌ ํ™•์žฅ**
1342
+ - ๊ฐ ์”ฌ ์˜คํ”„๋‹์— ๋ถ„์œ„๊ธฐ ๋ฌ˜์‚ฌ ์ถ”๊ฐ€
1343
+ - ์บ๋ฆญํ„ฐ ๋“ฑ์žฅ ์‹œ ์ƒ์„ธํ•œ ๋น„์ฃผ์–ผ ๋ฌ˜์‚ฌ
1344
+ - ์ค‘์š”ํ•œ ์ˆœ๊ฐ„์˜ ์Šฌ๋กœ์šฐ๋ชจ์…˜ ํšจ๊ณผ
1345
+ - ์ „ํ™˜ ์žฅ๋ฉด๊ณผ ๋ธŒ๋ฆฟ์ง€ ์ถ”๊ฐ€
1346
+
1347
+ 3. **์ƒˆ๋กœ์šด ๋น„ํŠธ ์‚ฝ์ž…**
1348
+ - ๊ธด์žฅ ์™„๊ธ‰์„ ์œ„ํ•œ ํ˜ธํก ์žฅ๋ฉด
1349
+ - ์บ๋ฆญํ„ฐ์˜ ์ผ์ƒ์  ํ–‰๋™ ์ถ”๊ฐ€
1350
+ - ๊ด€๊ณ„๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ์ž‘์€ ์ˆœ๊ฐ„๋“ค
1351
+ - ๋ณต์„ ์ด ๋  ์ˆ˜ ์žˆ๋Š” ๋””ํ…Œ์ผ
1352
+
1353
+ 4. **{genre} ์žฅ๋ฅด ๊ฐ•ํ™”**
1354
+ ๋‹ค์Œ ์žฅ๋ฅด ์š”์†Œ๋ฅผ ๋” ์ถ”๊ฐ€ํ•˜์„ธ์š”:
1355
+ {chr(10).join([f" - {element}" for element in GENRE_TEMPLATES[genre]['key_elements']])}
1356
+
1357
+ 5. **๊ตฌ์ฒด์  ํ™•์žฅ ์œ„์น˜**
1358
+ ๊ฐ ์”ฌ๋ณ„๋กœ ์ •ํ™•ํžˆ ์–ด๋””์— ๋ฌด์—‡์„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•˜๋Š”์ง€ ๋ช…์‹œํ•˜์„ธ์š”:
1359
+ [์”ฌ ๋ฒˆํ˜ธ] - [ํ™•์žฅ ๋‚ด์šฉ] - [์˜ˆ์ƒ ์ถ”๊ฐ€ ์ค„ ์ˆ˜]
1360
+
1361
+ **๋ชฉํ‘œ: ์›๋ณธ์˜ 2๋ฐฐ ๋ถ„๋Ÿ‰์œผ๋กœ ํ™•์žฅํ•˜๋˜, ์ž์—ฐ์Šค๋Ÿฝ๊ณ  ํ•„์š”ํ•œ ๋‚ด์šฉ๋งŒ ์ถ”๊ฐ€**""",
1362
+
1363
+ "English": f"""You are a script doctor. Review {act} and provide expansion instructions.
1364
+
1365
+ **Current Length:** {current_pages:.1f} pages ({current_lines} lines)
1366
+ **Target Length:** {target_pages} pages
1367
+ **Additional Needed:** {expansion_needed:.1f} pages (approx {int(expansion_needed * 55)} lines)
1368
+
1369
+ **Written Content:**
1370
+ {act_content}
1371
+
1372
+ **Expansion Analysis & Instructions:**
1373
+
1374
+ 1. **Dialogue Expansion Opportunities**
1375
+ Review each dialogue sequence and add:
1376
+ - Subtext to rushed conversations
1377
+ - Emotional beats and reactions
1378
+ - Deeper conflict exploration
1379
+ - Lines revealing character interior
1380
+
1381
+ 2. **Action/Description Expansion**
1382
+ - Atmosphere description at scene openings
1383
+ - Detailed visual when characters appear
1384
+ - Slow-motion effect for key moments
1385
+ - Transition scenes and bridges
1386
+
1387
+ 3. **New Beat Insertions**
1388
+ - Breathing scenes for pacing
1389
+ - Character routine actions
1390
+ - Small relationship moments
1391
+ - Foreshadowing details
1392
+
1393
+ 4. **{genre} Genre Enhancement**
1394
+ Add more of these genre elements:
1395
+ {chr(10).join([f" - {element}" for element in GENRE_TEMPLATES[genre]['key_elements']])}
1396
+
1397
+ 5. **Specific Expansion Locations**
1398
+ Specify exactly where and what to add per scene:
1399
+ [Scene Number] - [Expansion Content] - [Estimated Additional Lines]
1400
+
1401
+ **Goal: Expand to double the original length with natural, necessary content**"""
1402
  }
1403
+
1404
  return lang_prompts.get(language, lang_prompts["English"])
1405
 
 
1406
  def create_expansion_writer_prompt(self, act: str, original_content: str,
1407
  expansion_notes: str, screenplay_type: str,
1408
  language: str) -> str:
 
1412
  target_lines = target_pages * 55
1413
 
1414
  lang_prompts = {
1415
+ "Korean": f"""์›๋ณธ {act}๋ฅผ ํ™•์žฅ ์ง€์‹œ์‚ฌํ•ญ์— ๋”ฐ๋ผ ๋‹ค์‹œ ์ž‘์„ฑํ•˜์„ธ์š”.
1416
+
1417
+ **๋ชฉํ‘œ ๋ถ„๋Ÿ‰:** {target_pages}ํŽ˜์ด์ง€ ({target_lines}์ค„)
1418
+
1419
+ **์›๋ณธ ์ดˆ๊ณ :**
1420
+ {original_content}
1421
+
1422
+ **ํ™•์žฅ ์ง€์‹œ์‚ฌํ•ญ:**
1423
+ {expansion_notes}
1424
+
1425
+ **ํ™•์žฅ ์ž‘์„ฑ ์›์น™:**
1426
+
1427
+ 1. **๊ตฌ์กฐ ์œ ์ง€**
1428
+ - ์›๋ณธ์˜ ์”ฌ ์ˆœ์„œ์™€ ํ•ต์‹ฌ ์‚ฌ๊ฑด ์œ ์ง€
1429
+ - ์Šคํ† ๋ฆฌ ์ง„ํ–‰์˜ ๋…ผ๋ฆฌ์„ฑ ๋ณด์กด
1430
+ - ์บ๋ฆญํ„ฐ ์•„ํฌ์˜ ์ผ๊ด€์„ฑ
1431
+
1432
+ 2. **์ž์—ฐ์Šค๋Ÿฌ์šด ํ™•์žฅ**
1433
+ - ์ถ”๊ฐ€ ๋‚ด์šฉ์ด ์–ต์ง€์Šค๋Ÿฝ์ง€ ์•Š๊ฒŒ
1434
+ - ๊ธฐ์กด ๋‚ด์šฉ๊ณผ ์œ ๊ธฐ์ ์œผ๋กœ ์—ฐ๊ฒฐ
1435
+ - ํŽ˜์ด์‹ฑ์„ ํ•ด์น˜์ง€ ์•Š๋Š” ์„ ์—์„œ
1436
+
1437
+ 3. **ํ’ˆ์งˆ ํ–ฅ์ƒ**
1438
+ - ๋” ๊นŠ์€ ๊ฐ์ • ํ‘œํ˜„
1439
+ - ๋” ์„ ๋ช…ํ•œ ์‹œ๊ฐ์  ์ด๋ฏธ์ง€
1440
+ - ๋” ๊ฐ•๋ ฅํ•œ ๋“œ๋ผ๋งˆํ‹ฑ ์ž„ํŒฉํŠธ
1441
+
1442
+ 4. **ํฌ๋งท ์ค€์ˆ˜**
1443
+ - ํ‘œ์ค€ ์‹œ๋‚˜๋ฆฌ์˜ค ํฌ๋งท ์—„๊ฒฉํžˆ ์ค€์ˆ˜
1444
+ - ์ ์ ˆํ•œ ์—ฌ๋ฐฑ๊ณผ ๊ฐ„๊ฒฉ
1445
+ - ์ฝ๊ธฐ ์‰ฌ์šด ๊ตฌ์„ฑ
1446
+
1447
+ **๋ฐ˜๋“œ์‹œ {target_lines}์ค„ ์ด์ƒ์˜ ์™„์ „ํ•œ ํ™•์žฅ ๋ฒ„์ „์„ ์ž‘์„ฑํ•˜์„ธ์š”.**""",
1448
+
1449
+ "English": f"""Rewrite {act} following expansion instructions.
1450
+
1451
+ **Target Length:** {target_pages} pages ({target_lines} lines)
1452
+
1453
+ **Original Draft:**
1454
+ {original_content}
1455
+
1456
+ **Expansion Instructions:**
1457
+ {expansion_notes}
1458
+
1459
+ **Expansion Principles:**
1460
+
1461
+ 1. **Structure Maintenance**
1462
+ - Keep original scene order and key events
1463
+ - Preserve story progression logic
1464
+ - Character arc consistency
1465
+
1466
+ 2. **Natural Expansion**
1467
+ - Additional content not forced
1468
+ - Organically connected to existing
1469
+ - Without harming pacing
1470
+
1471
+ 3. **Quality Enhancement**
1472
+ - Deeper emotional expression
1473
+ - Clearer visual imagery
1474
+ - Stronger dramatic impact
1475
+
1476
+ 4. **Format Compliance**
1477
+ - Strict standard screenplay format
1478
+ - Proper margins and spacing
1479
+ - Reader-friendly composition
1480
+
1481
+ **MUST write complete expanded version of {target_lines}+ lines.**"""
1482
  }
1483
+
1484
  return lang_prompts.get(language, lang_prompts["English"])
1485
 
1486
  def create_final_reviewer_prompt(self, complete_screenplay: str,