update: pipeline, search, clip, embedding fixes
This commit is contained in:
@@ -1967,7 +1967,7 @@ async fn main() -> Result<()> {
|
||||
|
||||
// Store ASR sentence pre_chunks
|
||||
let mut asr_pre_chunk_ids = Vec::new();
|
||||
for seg in asr_result.segments.iter() {
|
||||
for (i, seg) in asr_result.segments.iter().enumerate() {
|
||||
let start_frame = FrameTime::from_seconds(seg.start, fps).frames();
|
||||
let end_frame = FrameTime::from_seconds(seg.end, fps).frames();
|
||||
let pre_chunk = momentry_core::core::db::postgres_db::PreChunk {
|
||||
@@ -1985,13 +1985,13 @@ async fn main() -> Result<()> {
|
||||
chunk_id: None,
|
||||
created_at: String::new(),
|
||||
};
|
||||
let pre_chunk_id = db.store_pre_chunk(&pre_chunk).await?;
|
||||
asr_pre_chunk_ids.push(pre_chunk_id);
|
||||
db.store_pre_chunk(&uuid, "asr", serde_json::to_value(&pre_chunk)?).await?;
|
||||
asr_pre_chunk_ids.push(i as i64);
|
||||
}
|
||||
|
||||
// Store CUT scene pre_chunks
|
||||
let mut cut_pre_chunk_ids = Vec::new();
|
||||
for scene in &cut_result.scenes {
|
||||
for (i, scene) in cut_result.scenes.iter().enumerate() {
|
||||
let pre_chunk = momentry_core::core::db::postgres_db::PreChunk {
|
||||
id: 0,
|
||||
file_id,
|
||||
@@ -2009,8 +2009,8 @@ async fn main() -> Result<()> {
|
||||
chunk_id: None,
|
||||
created_at: String::new(),
|
||||
};
|
||||
let pre_chunk_id = db.store_pre_chunk(&pre_chunk).await?;
|
||||
cut_pre_chunk_ids.push(pre_chunk_id);
|
||||
db.store_pre_chunk(&uuid, "cut", serde_json::to_value(&pre_chunk)?).await?;
|
||||
cut_pre_chunk_ids.push(i as i64);
|
||||
}
|
||||
|
||||
// Store time-based pre_chunks (every 10 seconds)
|
||||
@@ -2037,8 +2037,8 @@ async fn main() -> Result<()> {
|
||||
chunk_id: None,
|
||||
created_at: String::new(),
|
||||
};
|
||||
let pre_chunk_id = db.store_pre_chunk(&pre_chunk).await?;
|
||||
time_pre_chunk_ids.push(pre_chunk_id);
|
||||
db.store_pre_chunk(&uuid, "time", serde_json::to_value(&pre_chunk)?).await?;
|
||||
time_pre_chunk_ids.push(time_pre_chunk_ids.len() as i64);
|
||||
time_start = time_end;
|
||||
}
|
||||
|
||||
@@ -2117,7 +2117,7 @@ async fn main() -> Result<()> {
|
||||
frame_path: None,
|
||||
created_at: String::new(),
|
||||
};
|
||||
db.store_frame(&frame).await?;
|
||||
db.store_frame(&uuid, *frame_num as i64, serde_json::to_value(&frame)?).await?;
|
||||
}
|
||||
|
||||
println!("Stored {} frames", all_frames.len());
|
||||
@@ -2294,7 +2294,6 @@ async fn main() -> Result<()> {
|
||||
.collect();
|
||||
|
||||
let story_type = if story_chunks.is_empty() {
|
||||
// Fall back to sentence chunks
|
||||
story_chunks = all_chunks
|
||||
.iter()
|
||||
.filter(|c| c.chunk_type == ChunkType::Sentence && c.text_content.is_some())
|
||||
@@ -2311,7 +2310,6 @@ async fn main() -> Result<()> {
|
||||
|
||||
println!("Found {} {} scenes", story_chunks.len(), story_type);
|
||||
|
||||
// Generate story for each scene
|
||||
for (i, story_chunk) in story_chunks.iter().enumerate() {
|
||||
println!("\n=== Scene {} ===", i + 1);
|
||||
println!(
|
||||
@@ -2320,21 +2318,17 @@ async fn main() -> Result<()> {
|
||||
story_chunk.end_time().seconds()
|
||||
);
|
||||
|
||||
// Get context: expand time range by 5 seconds before and after
|
||||
let context_start = (story_chunk.start_time().seconds() - 5.0).max(0.0);
|
||||
let context_end = (story_chunk.end_time().seconds() + 5.0).min(duration);
|
||||
|
||||
// Get chunks in context range (sentence chunks with ASR text)
|
||||
let context_chunks = db
|
||||
.get_chunks_by_time_range(file_id, context_start, context_end)
|
||||
.get_chunks_by_time_range(&uuid, context_start, context_end)
|
||||
.await?;
|
||||
|
||||
// Get frames in context range
|
||||
let context_frames = db
|
||||
.get_frames_by_time_range(file_id, context_start, context_end)
|
||||
.get_frames_by_time_range(&uuid, context_start, context_end)
|
||||
.await?;
|
||||
|
||||
// Build story
|
||||
let mut story = String::new();
|
||||
story.push_str(&format!(
|
||||
"Scene {} ({:.1}s - {:.1}s)\n\n",
|
||||
@@ -2343,34 +2337,30 @@ async fn main() -> Result<()> {
|
||||
story_chunk.end_time().seconds()
|
||||
));
|
||||
|
||||
// Add audio/text content
|
||||
let sentence_chunks: Vec<&Chunk> = context_chunks
|
||||
let sentence_chunks: Vec<&serde_json::Value> = context_chunks
|
||||
.iter()
|
||||
.filter(|c| c.chunk_type == ChunkType::Sentence)
|
||||
.filter(|c| c["chunk_type"] == "sentence")
|
||||
.collect();
|
||||
|
||||
if !sentence_chunks.is_empty() {
|
||||
story.push_str("【Speech】\n");
|
||||
for sc in &sentence_chunks {
|
||||
if let Some(text) = &sc.text_content {
|
||||
if let Some(text) = sc["text_content"].as_str() {
|
||||
story.push_str(&format!(" - {}\n", text));
|
||||
}
|
||||
}
|
||||
story.push('\n');
|
||||
}
|
||||
|
||||
// Aggregate YOLO objects
|
||||
let mut all_objects: std::collections::HashMap<String, u32> =
|
||||
std::collections::HashMap::new();
|
||||
for frame in &context_frames {
|
||||
if let Some(objects) = &frame.yolo_objects {
|
||||
if let Some(arr) = objects.as_array() {
|
||||
for obj in arr {
|
||||
if let Some(class_name) =
|
||||
obj.get("class_name").and_then(|v| v.as_str())
|
||||
{
|
||||
*all_objects.entry(class_name.to_string()).or_insert(0) += 1;
|
||||
}
|
||||
if let Some(objects) = frame["yolo_objects"].as_array() {
|
||||
for obj in objects {
|
||||
if let Some(class_name) =
|
||||
obj.get("class_name").and_then(|v| v.as_str())
|
||||
{
|
||||
*all_objects.entry(class_name.to_string()).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2386,16 +2376,13 @@ async fn main() -> Result<()> {
|
||||
story.push('\n');
|
||||
}
|
||||
|
||||
// Aggregate OCR text
|
||||
let mut all_texts: Vec<String> = Vec::new();
|
||||
for frame in &context_frames {
|
||||
if let Some(texts) = &frame.ocr_results {
|
||||
if let Some(arr) = texts.as_array() {
|
||||
for txt in arr {
|
||||
if let Some(text) = txt.get("text").and_then(|v| v.as_str()) {
|
||||
if !text.is_empty() && text.len() > 2 {
|
||||
all_texts.push(text.to_string());
|
||||
}
|
||||
if let Some(texts) = frame["ocr_results"].as_array() {
|
||||
for txt in texts {
|
||||
if let Some(text) = txt.get("text").and_then(|v| v.as_str()) {
|
||||
if !text.is_empty() && text.len() > 2 {
|
||||
all_texts.push(text.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2410,13 +2397,10 @@ async fn main() -> Result<()> {
|
||||
story.push('\n');
|
||||
}
|
||||
|
||||
// Aggregate faces
|
||||
let mut face_count = 0;
|
||||
for frame in &context_frames {
|
||||
if let Some(faces) = &frame.face_results {
|
||||
if let Some(arr) = faces.as_array() {
|
||||
face_count += arr.len();
|
||||
}
|
||||
if let Some(faces) = frame["face_results"].as_array() {
|
||||
face_count += faces.len();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user