Update app.py
Browse files
app.py
CHANGED
|
@@ -89,42 +89,41 @@ def generate_transcript(detection_result, ocr_result):
|
|
| 89 |
ocr_result
|
| 90 |
)
|
| 91 |
|
| 92 |
-
def generate_structural_dialogue(detection_result):
|
| 93 |
texts = detection_result.get("texts", [])
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 96 |
)
|
| 97 |
|
| 98 |
dialogue_lines = []
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
for text_id, text in enumerate(texts):
|
| 107 |
-
assoc_list = assoc_by_text.get(text_id, [])
|
| 108 |
-
|
| 109 |
-
if assoc_list:
|
| 110 |
-
# pega a associação mais forte
|
| 111 |
-
best = max(
|
| 112 |
-
assoc_list,
|
| 113 |
-
key=lambda x: x["score"]
|
| 114 |
-
)
|
| 115 |
-
line = (
|
| 116 |
-
f"Text {text_id} → "
|
| 117 |
-
f"Character {best['character_id']} "
|
| 118 |
-
f"(score: {best['score']:.2f})"
|
| 119 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
else:
|
| 121 |
-
line = f"Text {text_id} →
|
| 122 |
|
| 123 |
dialogue_lines.append(line)
|
| 124 |
|
| 125 |
return "\n".join(dialogue_lines)
|
| 126 |
|
| 127 |
|
|
|
|
| 128 |
# ===============================
|
| 129 |
# UI
|
| 130 |
# ===============================
|
|
|
|
| 89 |
ocr_result
|
| 90 |
)
|
| 91 |
|
| 92 |
+
def generate_structural_dialogue(detection_result, threshold=0.4):
|
| 93 |
texts = detection_result.get("texts", [])
|
| 94 |
+
characters = detection_result.get("characters", [])
|
| 95 |
+
scores = detection_result.get(
|
| 96 |
+
"text_character_matching_scores", []
|
| 97 |
)
|
| 98 |
|
| 99 |
dialogue_lines = []
|
| 100 |
|
| 101 |
+
for text_id in range(len(texts)):
|
| 102 |
+
if text_id < len(scores) and scores[text_id]:
|
| 103 |
+
char_scores = scores[text_id]
|
| 104 |
+
best_char = max(
|
| 105 |
+
range(len(char_scores)),
|
| 106 |
+
key=lambda i: char_scores[i]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
)
|
| 108 |
+
best_score = char_scores[best_char]
|
| 109 |
+
|
| 110 |
+
if best_score >= threshold:
|
| 111 |
+
line = (
|
| 112 |
+
f"Text {text_id} → "
|
| 113 |
+
f"Character {best_char} "
|
| 114 |
+
f"(score: {best_score:.2f})"
|
| 115 |
+
)
|
| 116 |
+
else:
|
| 117 |
+
line = f"Text {text_id} → Narration / Uncertain"
|
| 118 |
else:
|
| 119 |
+
line = f"Text {text_id} → Narration / Uncertain"
|
| 120 |
|
| 121 |
dialogue_lines.append(line)
|
| 122 |
|
| 123 |
return "\n".join(dialogue_lines)
|
| 124 |
|
| 125 |
|
| 126 |
+
|
| 127 |
# ===============================
|
| 128 |
# UI
|
| 129 |
# ===============================
|