improve app.py
Browse files- app.py +40 -18
- lec2note/segmentation/semantic_segmenter.py +2 -2
- lec2note/segmentation/visual_merger.py +1 -1
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 |
-
|
|
|
|
| 35 |
|
| 36 |
# Run pipeline via subprocess to avoid blocking UI; capture logs
|
| 37 |
with st.spinner("Running Lec2Note2 pipeline β¦"):
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
st.error("β Pipeline failed. See logs below.")
|
| 53 |
with st.expander("Show logs"):
|
| 54 |
-
st.code(
|
| 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.
|
| 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"]
|