Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -485,6 +485,11 @@ class ScreenplayGenerationSystem:
|
|
485 |
"Authorization": f"Bearer {self.api_key}"
|
486 |
}
|
487 |
|
|
|
|
|
|
|
|
|
|
|
488 |
def call_llm_streaming(self, messages: List[Dict[str, str]], max_tokens: int = 8000) -> Generator[str, None, None]:
|
489 |
"""LLM ํธ์ถ - ๊ฐ์ ๋ ๋ฒ์ """
|
490 |
try:
|
@@ -743,23 +748,29 @@ class ScreenplayGenerationSystem:
|
|
743 |
previous_acts: Dict) -> Generator[Tuple[ActProgress, str], None, None]:
|
744 |
"""๋ง๋ณ ์๋๋ฆฌ์ค ์์ฑ - ๊ฐ์ ๋ ๋ฒ์ """
|
745 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
746 |
try:
|
747 |
self.current_session_id = session_id
|
748 |
self.planning_data = planning_data
|
749 |
|
750 |
# ์ธ์
์ ๋ณด ๋ณต์
|
751 |
-
session_data =
|
752 |
if session_data:
|
753 |
self.original_query = session_data.get('user_query', '')
|
754 |
|
755 |
stages = ACT_WRITING_STAGES.get(act_name, [])
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
current_expert="",
|
761 |
-
status="in_progress"
|
762 |
-
)
|
763 |
|
764 |
act_content = ""
|
765 |
|
@@ -853,44 +864,81 @@ class ScreenplayGenerationSystem:
|
|
853 |
logger.error(f"Act generation error: {e}\n{traceback.format_exc()}")
|
854 |
act_progress.status = "error"
|
855 |
yield act_progress, f"โ ์ค๋ฅ: {str(e)}"
|
856 |
-
|
857 |
def _clean_output(self, text: str) -> str:
|
858 |
"""์ถ๋ ฅ ํ
์คํธ ์ ๋ฆฌ"""
|
859 |
-
#
|
860 |
-
format_terms = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
861 |
|
862 |
lines = text.split('\n')
|
863 |
cleaned_lines = []
|
864 |
|
865 |
for line in lines:
|
866 |
# ํฌ๋งท ์ฉ์ด๋ ์ ์ง
|
867 |
-
if any(term in line for term in format_terms):
|
868 |
cleaned_lines.append(line)
|
869 |
else:
|
870 |
-
#
|
871 |
-
|
|
|
|
|
|
|
872 |
# ๋ถ์์ ํ ๋ถ๋ถ ์ ๊ฑฐ
|
873 |
-
line = line.replace("......", "").replace(".....", "").replace("...", "")
|
874 |
cleaned_lines.append(line)
|
875 |
else:
|
876 |
-
# ์์ด๊ฐ ํฌํจ๋
|
877 |
-
|
|
|
878 |
|
879 |
return '\n'.join(cleaned_lines)
|
880 |
-
|
|
|
|
|
881 |
def _contains_english(self, text: str) -> bool:
|
882 |
-
"""์์ด ํฌํจ ์ฌ๋ถ ํ์ธ (ํฌ๋งท ์ฉ์ด ์ ์ธ)"""
|
883 |
-
|
|
|
|
|
|
|
|
|
|
|
884 |
|
885 |
# ํฌ๋งท ์ฉ์ด ์ ๊ฑฐ ํ ํ์ธ
|
886 |
test_text = text
|
887 |
-
for term in
|
888 |
test_text = test_text.replace(term, "")
|
889 |
|
890 |
-
# ์ํ๋ฒณ ์ฐ์
|
891 |
import re
|
892 |
-
english_pattern = re.compile(r'[a-zA-Z]{
|
893 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
894 |
|
895 |
def _validate_and_clean_screenplay(self, content: str) -> str:
|
896 |
"""์๋๋ฆฌ์ค ๊ฒ์ฆ ๋ฐ ์ ๋ฆฌ"""
|
@@ -1107,6 +1155,23 @@ class ScreenplayGenerationSystem:
|
|
1107 |
summary += f"[{act}]\n{content[:300]}...\n"
|
1108 |
return summary[:1000]
|
1109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1110 |
# UI ํจ์๋ค
|
1111 |
def create_act_progress_display(act_progress: ActProgress) -> str:
|
1112 |
"""๋ง๋ณ ์งํ ์ํฉ ํ์"""
|
|
|
485 |
"Authorization": f"Bearer {self.api_key}"
|
486 |
}
|
487 |
|
488 |
+
def get_session_data(self, session_id: str) -> Optional[Dict]:
|
489 |
+
"""์ธ์
๋ฐ์ดํฐ ์กฐํ - ์ธ์คํด์ค ๋ฉ์๋"""
|
490 |
+
return ScreenplayDatabase.get_session_data(session_id)
|
491 |
+
|
492 |
+
|
493 |
def call_llm_streaming(self, messages: List[Dict[str, str]], max_tokens: int = 8000) -> Generator[str, None, None]:
|
494 |
"""LLM ํธ์ถ - ๊ฐ์ ๋ ๋ฒ์ """
|
495 |
try:
|
|
|
748 |
previous_acts: Dict) -> Generator[Tuple[ActProgress, str], None, None]:
|
749 |
"""๋ง๋ณ ์๋๋ฆฌ์ค ์์ฑ - ๊ฐ์ ๋ ๋ฒ์ """
|
750 |
|
751 |
+
# act_progress๋ฅผ ๋จผ์ ์ด๊ธฐํ
|
752 |
+
act_progress = ActProgress(
|
753 |
+
act_name=act_name,
|
754 |
+
current_stage=0,
|
755 |
+
total_stages=0,
|
756 |
+
current_expert="",
|
757 |
+
status="initializing"
|
758 |
+
)
|
759 |
+
|
760 |
try:
|
761 |
self.current_session_id = session_id
|
762 |
self.planning_data = planning_data
|
763 |
|
764 |
# ์ธ์
์ ๋ณด ๋ณต์
|
765 |
+
session_data = self.get_session_data(session_id) # ๋ฉ์๋ ํธ์ถ ์์
|
766 |
if session_data:
|
767 |
self.original_query = session_data.get('user_query', '')
|
768 |
|
769 |
stages = ACT_WRITING_STAGES.get(act_name, [])
|
770 |
+
|
771 |
+
# act_progress ์
๋ฐ์ดํธ
|
772 |
+
act_progress.total_stages = len(stages)
|
773 |
+
act_progress.status = "in_progress"
|
|
|
|
|
|
|
774 |
|
775 |
act_content = ""
|
776 |
|
|
|
864 |
logger.error(f"Act generation error: {e}\n{traceback.format_exc()}")
|
865 |
act_progress.status = "error"
|
866 |
yield act_progress, f"โ ์ค๋ฅ: {str(e)}"
|
867 |
+
|
868 |
def _clean_output(self, text: str) -> str:
|
869 |
"""์ถ๋ ฅ ํ
์คํธ ์ ๋ฆฌ"""
|
870 |
+
# ์๋๋ฆฌ์ค ํฌ๋งท ์ฉ์ด ํ์ฅ
|
871 |
+
format_terms = [
|
872 |
+
"INT.", "EXT.", "CUT TO:", "FADE IN:", "FADE OUT:",
|
873 |
+
"DISSOLVE TO:", "CONT'D", "O.S.", "V.O.", "POV",
|
874 |
+
"MONTAGE", "FLASHBACK", "DREAM SEQUENCE", "CLOSE UP",
|
875 |
+
"WIDE SHOT", "ESTABLISHING SHOT"
|
876 |
+
]
|
877 |
+
|
878 |
+
# ํ๊ตญ์ด ์๋๋ฆฌ์ค์์ ์ฌ์ฉ๋๋ ์ฝ์ด๋ค
|
879 |
+
korean_screenplay_abbreviations = [
|
880 |
+
"CG", "SFX", "BGM", "OST", "NG", "OK", "VIP", "CEO", "AI",
|
881 |
+
"DJ", "MC", "PD", "VJ", "IT", "PC", "TV", "DVD", "USB"
|
882 |
+
]
|
883 |
|
884 |
lines = text.split('\n')
|
885 |
cleaned_lines = []
|
886 |
|
887 |
for line in lines:
|
888 |
# ํฌ๋งท ์ฉ์ด๋ ์ ์ง
|
889 |
+
if any(term in line.upper() for term in format_terms):
|
890 |
cleaned_lines.append(line)
|
891 |
else:
|
892 |
+
# ์ฝ์ด๊ฐ ํฌํจ๋ ๊ฒฝ์ฐ ํ์ฉ
|
893 |
+
contains_abbr = any(abbr in line for abbr in korean_screenplay_abbreviations)
|
894 |
+
|
895 |
+
# ์์ด ๊ฐ์ง (์ฝ์ด ์ ์ธ)
|
896 |
+
if contains_abbr or not self._contains_english(line):
|
897 |
# ๋ถ์์ ํ ๋ถ๋ถ ์ ๊ฑฐ
|
898 |
+
line = line.replace("......", "").replace(".....", "").replace("...", ".")
|
899 |
cleaned_lines.append(line)
|
900 |
else:
|
901 |
+
# ์ค์ ์์ด๊ฐ ํฌํจ๋ ๊ฒฝ์ฐ๋ง ๊ฒฝ๊ณ
|
902 |
+
if len(line.strip()) > 10: # ์งง์ ์ค์ ๋ฌด์
|
903 |
+
logger.debug(f"Skipping potential English line: {line[:50]}")
|
904 |
|
905 |
return '\n'.join(cleaned_lines)
|
906 |
+
|
907 |
+
|
908 |
+
|
909 |
def _contains_english(self, text: str) -> bool:
|
910 |
+
"""์์ด ํฌํจ ์ฌ๋ถ ํ์ธ (ํฌ๋งท ์ฉ์ด ๋ฐ ํ์ฉ ๋จ์ด ์ ์ธ)"""
|
911 |
+
# ์๋๋ฆฌ์ค์์ ํ์ฉ๋๋ ์ฉ์ด๋ค
|
912 |
+
allowed_terms = [
|
913 |
+
"INT", "EXT", "CUT", "FADE", "DISSOLVE", "CONT'D",
|
914 |
+
"O.S.", "V.O.", "POV", "CG", "SFX", "BGM", "OST",
|
915 |
+
"vs", "ex", "D", "Main", "Conflict", "wang", "PO", "V"
|
916 |
+
]
|
917 |
|
918 |
# ํฌ๋งท ์ฉ์ด ์ ๊ฑฐ ํ ํ์ธ
|
919 |
test_text = text
|
920 |
+
for term in allowed_terms:
|
921 |
test_text = test_text.replace(term, "")
|
922 |
|
923 |
+
# ์ํ๋ฒณ ์ฐ์ 4๊ฐ ์ด์์ด๋ฉด ์์ด๋ก ํ๋จ (3๊ฐ์์ 4๊ฐ๋ก ๋ณ๊ฒฝ)
|
924 |
import re
|
925 |
+
english_pattern = re.compile(r'[a-zA-Z]{4,}')
|
926 |
+
matches = english_pattern.findall(test_text)
|
927 |
+
|
928 |
+
# ๋ฐ๊ฒฌ๋ ์์ด ๋จ์ด๊ฐ ์์ผ๋ฉด ๋ก๊น
ํ๊ณ ํ์ธ
|
929 |
+
if matches:
|
930 |
+
# ์ถ๊ฐ ํํฐ๋ง: ํ๊ตญ์ด ์์ ์ฝ์ด๋ ์ด๋์
์ ํ์ฉ
|
931 |
+
real_english = []
|
932 |
+
for match in matches:
|
933 |
+
if len(match) > 5: # 5์ ์ด์์ ์์ด ๋จ์ด๋ง ์ค์ ์์ด๋ก ํ๋จ
|
934 |
+
real_english.append(match)
|
935 |
+
|
936 |
+
if real_english:
|
937 |
+
logger.debug(f"Real English words found: {real_english}")
|
938 |
+
return True
|
939 |
+
|
940 |
+
return False
|
941 |
+
|
942 |
|
943 |
def _validate_and_clean_screenplay(self, content: str) -> str:
|
944 |
"""์๋๋ฆฌ์ค ๊ฒ์ฆ ๋ฐ ์ ๋ฆฌ"""
|
|
|
1155 |
summary += f"[{act}]\n{content[:300]}...\n"
|
1156 |
return summary[:1000]
|
1157 |
|
1158 |
+
|
1159 |
+
|
1160 |
+
@staticmethod
|
1161 |
+
def get_session_data(session_id: str) -> Optional[Dict]:
|
1162 |
+
"""์ธ์
๋ฐ์ดํฐ ์กฐํ"""
|
1163 |
+
with ScreenplayDatabase.get_db() as conn:
|
1164 |
+
cursor = conn.cursor()
|
1165 |
+
row = cursor.execute(
|
1166 |
+
'SELECT * FROM screenplay_sessions WHERE session_id = ?',
|
1167 |
+
(session_id,)
|
1168 |
+
).fetchone()
|
1169 |
+
if row:
|
1170 |
+
# Row ๊ฐ์ฒด๋ฅผ ๋์
๋๋ฆฌ๋ก ๋ณํ
|
1171 |
+
columns = [description[0] for description in cursor.description]
|
1172 |
+
return dict(zip(columns, row))
|
1173 |
+
return None
|
1174 |
+
|
1175 |
# UI ํจ์๋ค
|
1176 |
def create_act_progress_display(act_progress: ActProgress) -> str:
|
1177 |
"""๋ง๋ณ ์งํ ์ํฉ ํ์"""
|