LRU1 commited on
Commit
e04f2c1
Β·
1 Parent(s): dbae597

improve app.py

Browse files
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  from pathlib import Path
3
- import tempfile
4
- import subprocess
5
  import textwrap
6
 
7
  st.set_page_config(page_title="Lec2Note2 – Lecture-to-Notes", layout="wide")
@@ -31,27 +30,50 @@ if run_btn and video_file:
31
  output_md = vid_path.with_suffix(".md")
32
 
33
  st.info("Processing started. This may take several minutes depending on video length …")
34
- progress_txt = st.empty()
 
35
 
36
  # Run pipeline via subprocess to avoid blocking UI; capture logs
37
  with st.spinner("Running Lec2Note2 pipeline …"):
38
- result = subprocess.run(
39
- [
40
- "python",
41
- "-m",
42
- "lec2note.scripts.run_pipeline",
43
- "--video",
44
- str(vid_path),
45
- "--output",
46
- str(output_md),
47
- ],
48
- text=True,
49
- capture_output=True,
50
- )
51
- if result.returncode != 0:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  st.error("❌ Pipeline failed. See logs below.")
53
  with st.expander("Show logs"):
54
- st.code(result.stderr + "\n" + result.stdout)
55
  else:
56
  st.success("βœ… Notes generated!")
57
  md_content = output_md.read_text()
 
1
  import streamlit as st
2
  from pathlib import Path
3
+ import tempfile, subprocess, threading, queue
 
4
  import textwrap
5
 
6
  st.set_page_config(page_title="Lec2Note2 – Lecture-to-Notes", layout="wide")
 
30
  output_md = vid_path.with_suffix(".md")
31
 
32
  st.info("Processing started. This may take several minutes depending on video length …")
33
+ # container for live log streaming
34
+ log_container = st.container()
35
 
36
  # Run pipeline via subprocess to avoid blocking UI; capture logs
37
  with st.spinner("Running Lec2Note2 pipeline …"):
38
+ # launch pipeline in subprocess with unbuffered output
39
+ cmd = [
40
+ "python",
41
+ "-u", # unbuffer stdout
42
+ "-m",
43
+ "lec2note.scripts.run_pipeline",
44
+ "--video",
45
+ str(vid_path),
46
+ "--output",
47
+ str(output_md),
48
+ ]
49
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
50
+
51
+ log_queue: "queue.Queue[str]" = queue.Queue()
52
+
53
+ def _enqueue_output(pipe, q):
54
+ for line in iter(pipe.readline, ""):
55
+ q.put(line)
56
+ pipe.close()
57
+
58
+ threading.Thread(target=_enqueue_output, args=(proc.stdout, log_queue), daemon=True).start()
59
+
60
+ logs = ""
61
+ while True:
62
+ try:
63
+ line = log_queue.get(timeout=0.1)
64
+ except queue.Empty:
65
+ if proc.poll() is not None:
66
+ # process finished and queue empty
67
+ break
68
+ continue
69
+ logs += line
70
+ log_container.code(logs, language="bash")
71
+
72
+ result_code = proc.wait()
73
+ if result_code != 0:
74
  st.error("❌ Pipeline failed. See logs below.")
75
  with st.expander("Show logs"):
76
+ st.code(logs)
77
  else:
78
  st.success("βœ… Notes generated!")
79
  md_content = output_md.read_text()
lec2note/segmentation/semantic_segmenter.py CHANGED
@@ -39,8 +39,8 @@ class SemanticSegmenter: # noqa: D101
39
  buf_emb = embeddings[0]
40
  for i in range(1, len(slide_chunks)):
41
  sim = float(util.cos_sim(buf_emb, embeddings[i]))
42
- print("semantic sim:",sim)
43
- if sim > 0.7: # too similar => merge
44
  buffer["end"] = slide_chunks[i]["end"]
45
  else:
46
  refined.append(buffer)
 
39
  buf_emb = embeddings[0]
40
  for i in range(1, len(slide_chunks)):
41
  sim = float(util.cos_sim(buf_emb, embeddings[i]))
42
+ # print("semantic sim:",sim)
43
+ if sim > 0.55: # too similar => merge
44
  buffer["end"] = slide_chunks[i]["end"]
45
  else:
46
  refined.append(buffer)
lec2note/segmentation/visual_merger.py CHANGED
@@ -51,7 +51,7 @@ class VisualMerger: # noqa: D101
51
  except Exception as exc: # noqa: BLE001
52
  logger.warning("[VisualMerger] similarity calc failed: %s", exc)
53
  sim = 0.0 # force split
54
- print("visual sim:",sim)
55
  if sim >= sim_threshold:
56
  # merge: extend end and replace keyframe/path to current (last)
57
  buffer["end"] = mc["end"]
 
51
  except Exception as exc: # noqa: BLE001
52
  logger.warning("[VisualMerger] similarity calc failed: %s", exc)
53
  sim = 0.0 # force split
54
+ # print("visual sim:",sim)
55
  if sim >= sim_threshold:
56
  # merge: extend end and replace keyframe/path to current (last)
57
  buffer["end"] = mc["end"]