Update main_process/salamandra_router.py
Browse files
main_process/salamandra_router.py
CHANGED
|
@@ -1032,6 +1032,71 @@ class Free_Narration:
|
|
| 1032 |
|
| 1033 |
return state
|
| 1034 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1035 |
@router.post("/generate_salamandra_result", tags=["Salamandra Process"])
|
| 1036 |
async def generate_salamadra_result(
|
| 1037 |
sha1: str,
|
|
@@ -1457,6 +1522,8 @@ async def generate_salamadra_result(
|
|
| 1457 |
user_prompt = "Ejecuta la funci贸n Free_Narration"
|
| 1458 |
final_state, messages_registro = run_salamandra_agent(salamandraclient, final_state, tools, user_prompt, messages_registro, count)
|
| 1459 |
print("Free Narration guardada")
|
|
|
|
|
|
|
| 1460 |
|
| 1461 |
return {"status": "ok", "message": "Salamandra SRT, free_narration and CSV evaluation generated"}
|
| 1462 |
|
|
|
|
| 1032 |
|
| 1033 |
return state
|
| 1034 |
|
| 1035 |
+
def srt_update(srt_video, srt_video_modified):
|
| 1036 |
+
with open(srt_video, "r", encoding="utf-8") as f:
|
| 1037 |
+
srt_text = f.read()
|
| 1038 |
+
|
| 1039 |
+
srt_blocks = []
|
| 1040 |
+
srt_blocks_modified = []
|
| 1041 |
+
|
| 1042 |
+
pattern = re.compile(
|
| 1043 |
+
r"(\d+)\s+(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})\s+(.*?)(?=\n\d+\n|\Z)",
|
| 1044 |
+
re.S
|
| 1045 |
+
)
|
| 1046 |
+
|
| 1047 |
+
for match in pattern.finditer(srt_text):
|
| 1048 |
+
srt_blocks.append({
|
| 1049 |
+
"index": int(match.group(1)),
|
| 1050 |
+
"start": match.group(2),
|
| 1051 |
+
"end": match.group(3),
|
| 1052 |
+
"text": match.group(4).strip()
|
| 1053 |
+
})
|
| 1054 |
+
|
| 1055 |
+
for block in srt_blocks:
|
| 1056 |
+
original_text = block["text"]
|
| 1057 |
+
|
| 1058 |
+
match_name = re.match(r'\[([^\]]+)\]:\s*(.*)', original_text)
|
| 1059 |
+
if match_name:
|
| 1060 |
+
name = match_name.group(1).upper()
|
| 1061 |
+
content = match_name.group(2)
|
| 1062 |
+
|
| 1063 |
+
srt_blocks_modified.append({
|
| 1064 |
+
"index": block["index"],
|
| 1065 |
+
"start": block["start"],
|
| 1066 |
+
"end": block["end"],
|
| 1067 |
+
"text": f"{name}: {content}"
|
| 1068 |
+
})
|
| 1069 |
+
continue
|
| 1070 |
+
|
| 1071 |
+
match_ad = re.match(r'\(AD\):\s*(.*)', original_text)
|
| 1072 |
+
if match_ad:
|
| 1073 |
+
content = match_ad.group(1)
|
| 1074 |
+
|
| 1075 |
+
content = content.strip()
|
| 1076 |
+
if content.startswith('"') and content.endswith('"'): # quitamos las ""
|
| 1077 |
+
content = content[1:-1]
|
| 1078 |
+
|
| 1079 |
+
srt_blocks_modified.append({
|
| 1080 |
+
"index": block["index"],
|
| 1081 |
+
"start": block["start"],
|
| 1082 |
+
"end": block["end"],
|
| 1083 |
+
"text": f"(AD) {content}"
|
| 1084 |
+
})
|
| 1085 |
+
continue
|
| 1086 |
+
|
| 1087 |
+
srt_blocks_modified.append(block)
|
| 1088 |
+
|
| 1089 |
+
srt_final = ""
|
| 1090 |
+
for block in srt_blocks_modified:
|
| 1091 |
+
srt_final += (
|
| 1092 |
+
f"{block['index']}\n"
|
| 1093 |
+
f"{block['start']} --> {block['end']}\n"
|
| 1094 |
+
f"{block['text']}\n\n"
|
| 1095 |
+
)
|
| 1096 |
+
|
| 1097 |
+
with open(srt_video_modified, "w", encoding="utf-8") as f:
|
| 1098 |
+
f.write(srt_final)
|
| 1099 |
+
|
| 1100 |
@router.post("/generate_salamandra_result", tags=["Salamandra Process"])
|
| 1101 |
async def generate_salamadra_result(
|
| 1102 |
sha1: str,
|
|
|
|
| 1522 |
user_prompt = "Ejecuta la funci贸n Free_Narration"
|
| 1523 |
final_state, messages_registro = run_salamandra_agent(salamandraclient, final_state, tools, user_prompt, messages_registro, count)
|
| 1524 |
print("Free Narration guardada")
|
| 1525 |
+
|
| 1526 |
+
srt_update(srt_final,srt_final)
|
| 1527 |
|
| 1528 |
return {"status": "ok", "message": "Salamandra SRT, free_narration and CSV evaluation generated"}
|
| 1529 |
|