Update main_process/moe_router.py
Browse files- main_process/moe_router.py +67 -0
main_process/moe_router.py
CHANGED
|
@@ -357,6 +357,71 @@ class Valoracion_Final:
|
|
| 357 |
|
| 358 |
return state
|
| 359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
@router.post("/generate_moe_result", tags=["MoE Process"])
|
| 361 |
async def generate_salamadra_result(
|
| 362 |
sha1: str,
|
|
@@ -480,6 +545,8 @@ async def generate_salamadra_result(
|
|
| 480 |
state = valoracion_final(state, srt_final, csv_evaluacion)
|
| 481 |
tmp.close()
|
| 482 |
|
|
|
|
|
|
|
| 483 |
return {"status": "ok", "message": "Salamandra SRT, free_narration and CSV evaluation generated"}
|
| 484 |
|
| 485 |
@router.get("/download_moe_srt", tags=["MoE Process"])
|
|
|
|
| 357 |
|
| 358 |
return state
|
| 359 |
|
| 360 |
+
def srt_update(srt_video, srt_video_modified):
|
| 361 |
+
with open(srt_video, "r", encoding="utf-8") as f:
|
| 362 |
+
srt_text = f.read()
|
| 363 |
+
|
| 364 |
+
srt_blocks = []
|
| 365 |
+
srt_blocks_modified = []
|
| 366 |
+
|
| 367 |
+
pattern = re.compile(
|
| 368 |
+
r"(\d+)\s+(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})\s+(.*?)(?=\n\d+\n|\Z)",
|
| 369 |
+
re.S
|
| 370 |
+
)
|
| 371 |
+
|
| 372 |
+
for match in pattern.finditer(srt_text):
|
| 373 |
+
srt_blocks.append({
|
| 374 |
+
"index": int(match.group(1)),
|
| 375 |
+
"start": match.group(2),
|
| 376 |
+
"end": match.group(3),
|
| 377 |
+
"text": match.group(4).strip()
|
| 378 |
+
})
|
| 379 |
+
|
| 380 |
+
for block in srt_blocks:
|
| 381 |
+
original_text = block["text"]
|
| 382 |
+
|
| 383 |
+
match_name = re.match(r'\[([^\]]+)\]:\s*(.*)', original_text)
|
| 384 |
+
if match_name:
|
| 385 |
+
name = match_name.group(1).upper()
|
| 386 |
+
content = match_name.group(2)
|
| 387 |
+
|
| 388 |
+
srt_blocks_modified.append({
|
| 389 |
+
"index": block["index"],
|
| 390 |
+
"start": block["start"],
|
| 391 |
+
"end": block["end"],
|
| 392 |
+
"text": f"{name}: {content}"
|
| 393 |
+
})
|
| 394 |
+
continue
|
| 395 |
+
|
| 396 |
+
match_ad = re.match(r'\(AD\):\s*(.*)', original_text)
|
| 397 |
+
if match_ad:
|
| 398 |
+
content = match_ad.group(1)
|
| 399 |
+
|
| 400 |
+
content = content.strip()
|
| 401 |
+
if content.startswith('"') and content.endswith('"'): # quitamos las ""
|
| 402 |
+
content = content[1:-1]
|
| 403 |
+
|
| 404 |
+
srt_blocks_modified.append({
|
| 405 |
+
"index": block["index"],
|
| 406 |
+
"start": block["start"],
|
| 407 |
+
"end": block["end"],
|
| 408 |
+
"text": f"(AD) {content}"
|
| 409 |
+
})
|
| 410 |
+
continue
|
| 411 |
+
|
| 412 |
+
srt_blocks_modified.append(block)
|
| 413 |
+
|
| 414 |
+
srt_final = ""
|
| 415 |
+
for block in srt_blocks_modified:
|
| 416 |
+
srt_final += (
|
| 417 |
+
f"{block['index']}\n"
|
| 418 |
+
f"{block['start']} --> {block['end']}\n"
|
| 419 |
+
f"{block['text']}\n\n"
|
| 420 |
+
)
|
| 421 |
+
|
| 422 |
+
with open(srt_video_modified, "w", encoding="utf-8") as f:
|
| 423 |
+
f.write(srt_final)
|
| 424 |
+
|
| 425 |
@router.post("/generate_moe_result", tags=["MoE Process"])
|
| 426 |
async def generate_salamadra_result(
|
| 427 |
sha1: str,
|
|
|
|
| 545 |
state = valoracion_final(state, srt_final, csv_evaluacion)
|
| 546 |
tmp.close()
|
| 547 |
|
| 548 |
+
srt_update(srt_final,srt_final)
|
| 549 |
+
|
| 550 |
return {"status": "ok", "message": "Salamandra SRT, free_narration and CSV evaluation generated"}
|
| 551 |
|
| 552 |
@router.get("/download_moe_srt", tags=["MoE Process"])
|