Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 62 additions & 30 deletions ui/tabs/summarize_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,70 @@
from utils import api_get, api_post


def _get_video_choices(videos: list) -> dict:
"""Build video selection choices from video list."""
return {f"{v['title'][:60]} ({v['id'][:8]})": v for v in videos}
Comment on lines +9 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use specific type annotations instead of generic types.

The function uses generic list and dict types instead of specific type annotations. As per coding guidelines, all functions must be fully typed.

🔧 Proposed fix with specific type annotations
-def _get_video_choices(videos: list) -> dict:
+def _get_video_choices(videos: list[dict[str, str]]) -> dict[str, dict[str, str]]:
     """Build video selection choices from video list."""
     return {f"{v['title'][:60]} ({v['id'][:8]})": v for v in videos}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/tabs/summarize_tab.py` around lines 9 - 11, The function
_get_video_choices currently uses generic list and dict; update its signature to
use precise typing such as videos: Sequence[Mapping[str, str]] (or
list[dict[str, str]] if you prefer concrete lists) and a return type of
Dict[str, Mapping[str, str]] (or Dict[str, dict[str, str]]), and add the
necessary imports from typing (Sequence, Mapping, Dict) at the top of the
module; keep the implementation the same but with the new typed signature to
satisfy full typing requirements.



def _render_no_videos_message():
"""Display message when no indexed videos are available."""
st.info("No indexed videos yet. Go to the Ingest tab to add some.")
Comment on lines +14 to +16

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add explicit return type annotation.

The function is missing a return type annotation. As per coding guidelines, all functions must be fully typed.

🔧 Proposed fix
-def _render_no_videos_message():
+def _render_no_videos_message() -> None:
     """Display message when no indexed videos are available."""
     st.info("No indexed videos yet. Go to the Ingest tab to add some.")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def _render_no_videos_message():
"""Display message when no indexed videos are available."""
st.info("No indexed videos yet. Go to the Ingest tab to add some.")
def _render_no_videos_message() -> None:
"""Display message when no indexed videos are available."""
st.info("No indexed videos yet. Go to the Ingest tab to add some.")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/tabs/summarize_tab.py` around lines 14 - 16, The function
_render_no_videos_message lacks an explicit return type; update its signature to
include a return annotation (-> None) so it becomes def
_render_no_videos_message() -> None: while leaving the docstring and st.info
call unchanged; no other behavior or imports need modification.



def _render_summary_results(response: dict):
"""Render the summary and chapter results from API response."""
st.subheader(f"Summary: {response['title']}")
st.caption(f"Based on {response['chunk_count']} indexed segments")
st.markdown(response["overall_summary"])

chapter_summaries = response.get("chapter_summaries")
if chapter_summaries:
_render_chapter_summaries(chapter_summaries)
Comment on lines +19 to +27

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add explicit return type and use specific type for response parameter.

The function is missing a return type annotation and uses a generic dict type for the response parameter. As per coding guidelines, all functions must be fully typed.

🔧 Proposed fix
-def _render_summary_results(response: dict):
+def _render_summary_results(response: dict[str, Any]) -> None:
     """Render the summary and chapter results from API response."""
     st.subheader(f"Summary: {response['title']}")

Note: You may need to add from typing import Any at the top of the file if not already present.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/tabs/summarize_tab.py` around lines 19 - 27, Add explicit typing: import
Any from typing at the top if not present, then change the function signature of
_render_summary_results to accept a specific mapping type and return None, e.g.
def _render_summary_results(response: dict[str, Any]) -> None:, so the parameter
is typed and the function has an explicit return type; no other logic changes
required.



def _render_chapter_summaries(chapter_summaries: list):
"""Render individual chapter summaries as expanders."""
st.subheader("Chapter Summaries")
for chapter in chapter_summaries:
with st.expander(chapter["chapter"]):
st.write(chapter["summary"])
Comment on lines +30 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add explicit return type and use specific type for chapter_summaries parameter.

The function is missing a return type annotation and uses a generic list type for the chapter_summaries parameter. As per coding guidelines, all functions must be fully typed.

🔧 Proposed fix
-def _render_chapter_summaries(chapter_summaries: list):
+def _render_chapter_summaries(chapter_summaries: list[dict[str, str]]) -> None:
     """Render individual chapter summaries as expanders."""
     st.subheader("Chapter Summaries")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/tabs/summarize_tab.py` around lines 30 - 35, The _render_chapter_summaries
function lacks type annotations; change its signature to declare a return type
of None and a more specific parameter type (e.g., List[Dict[str, str]] or
Sequence[Mapping[str, str]]) so callers and linters know expected shapes, and
add the necessary typing imports (List and Dict or Sequence and Mapping) at the
top of the module; keep the body unchanged but update the signature to def
_render_chapter_summaries(chapter_summaries: List[Dict[str, str]]) -> None: (or
the Sequence/Mapping variant) to satisfy the typing guideline.



def _fetch_indexed_videos() -> list:
"""Fetch list of indexed videos from API."""
videos_data = api_get("/videos", params={"status": "indexed", "limit": 100})
if videos_data is None:
return []
return videos_data.get("videos", [])
Comment on lines +38 to +43

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use specific return type annotation.

The function uses a generic list return type instead of a specific type annotation. As per coding guidelines, all functions must be fully typed.

🔧 Proposed fix
-def _fetch_indexed_videos() -> list:
+def _fetch_indexed_videos() -> list[dict[str, Any]]:
     """Fetch list of indexed videos from API."""
     videos_data = api_get("/videos", params={"status": "indexed", "limit": 100})

Note: You may need to add from typing import Any at the top of the file if not already present.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/tabs/summarize_tab.py` around lines 38 - 43, The function
_fetch_indexed_videos currently returns a generic list; update its return type
to a concrete type such as list[dict[str, Any]] (or another specific Video type
if one exists) and add the necessary import from typing (e.g., Any) at the top
of the file; keep the existing behavior using api_get("/videos", ...) but change
the signature to reflect the precise element type and ensure the return
statements match that typed list.



def _handle_generate_summary(video_id: str, include_chapters: bool) -> dict | None:
"""Call API to generate summary and return response."""
with st.spinner("Summarizing... this may take a minute for long videos."):
return api_post(
"/summarize",
{"video_id": video_id, "include_chapters": include_chapters},
)
Comment on lines +46 to +52

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use specific return type annotation.

The function uses a generic dict return type instead of a specific type annotation. As per coding guidelines, all functions must be fully typed.

🔧 Proposed fix
-def _handle_generate_summary(video_id: str, include_chapters: bool) -> dict | None:
+def _handle_generate_summary(video_id: str, include_chapters: bool) -> dict[str, Any] | None:
     """Call API to generate summary and return response."""
     with st.spinner("Summarizing... this may take a minute for long videos."):

Note: You may need to add from typing import Any at the top of the file if not already present.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def _handle_generate_summary(video_id: str, include_chapters: bool) -> dict | None:
"""Call API to generate summary and return response."""
with st.spinner("Summarizing... this may take a minute for long videos."):
return api_post(
"/summarize",
{"video_id": video_id, "include_chapters": include_chapters},
)
def _handle_generate_summary(video_id: str, include_chapters: bool) -> dict[str, Any] | None:
"""Call API to generate summary and return response."""
with st.spinner("Summarizing... this may take a minute for long videos."):
return api_post(
"/summarize",
{"video_id": video_id, "include_chapters": include_chapters},
)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/tabs/summarize_tab.py` around lines 46 - 52, The function
_handle_generate_summary currently returns a generic dict; update its return
annotation to a specific type (e.g., create a SummaryResponse TypedDict or a
type alias like dict[str, Any]) and use that in the signature (SummaryResponse |
None or dict[str, Any] | None). Add the necessary imports (from typing import
Any or from typing import TypedDict) and adjust any downstream usage expecting
the old generic dict if needed; keep the api_post call as-is but annotate its
expected response type to match SummaryResponse so types line up with
_handle_generate_summary.



def render_summarize_tab():
"""Render the summarize tab UI."""
st.header("Summarize a Video")
st.caption("Generate an overall summary and per-chapter breakdown using map-reduce.")

videos_data = api_get("/videos", params={"status": "indexed", "limit": 100})
videos = _fetch_indexed_videos()

if not videos:
_render_no_videos_message()
return

video_choices = _get_video_choices(videos)
selected_label = st.selectbox("Select a video", list(video_choices.keys()))
selected_video = video_choices[selected_label]

include_chapters = st.checkbox("Include chapter summaries", value=True)

if videos_data and videos_data.get("videos"):
video_choices = {f"{v['title'][:60]} ({v['id'][:8]})": v for v in videos_data["videos"]}
selected_label = st.selectbox("Select a video", list(video_choices.keys()))
selected_video = video_choices[selected_label]

include_chapters = st.checkbox("Include chapter summaries", value=True)

if st.button("📝 Generate Summary", type="primary"):
with st.spinner("Summarizing... this may take a minute for long videos."):
resp = api_post(
"/summarize",
{
"video_id": selected_video["id"],
"include_chapters": include_chapters,
},
)

if resp:
st.subheader(f"Summary: {resp['title']}")
st.caption(f"Based on {resp['chunk_count']} indexed segments")
st.markdown(resp["overall_summary"])

if resp.get("chapter_summaries"):
st.subheader("Chapter Summaries")
for ch in resp["chapter_summaries"]:
with st.expander(ch["chapter"]):
st.write(ch["summary"])
else:
st.info("No indexed videos yet. Go to the Ingest tab to add some.")
if st.button("📝 Generate Summary", type="primary"):
response = _handle_generate_summary(selected_video["id"], include_chapters)
if response:
_render_summary_results(response)
Comment on lines 55 to +75

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Run mypy type checking on the modified file

# Check if mypy is available and run it
uvx mypy ui/tabs/summarize_tab.py --strict

Repository: varit05/Streaming-Video-RAG

Length of output: 115


🏁 Script executed:

cat -n ui/tabs/summarize_tab.py | sed -n '55,75p'

Repository: varit05/Streaming-Video-RAG

Length of output: 984


🏁 Script executed:

which mypy

Repository: varit05/Streaming-Video-RAG

Length of output: 117


🏁 Script executed:

python -m mypy ui/tabs/summarize_tab.py --strict 2>&1 | head -50

Repository: varit05/Streaming-Video-RAG

Length of output: 109


🏁 Script executed:

head -60 ui/tabs/summarize_tab.py | grep -E "^def |->|import"

Repository: varit05/Streaming-Video-RAG

Length of output: 459


🏁 Script executed:

rg "^def " ui/tabs/summarize_tab.py -A 2

Repository: varit05/Streaming-Video-RAG

Length of output: 1239


Add explicit return type annotation to render_summarize_tab().

The function is missing a return type annotation. According to coding guidelines, all functions must be fully typed. Since the function returns implicitly (None), add the -> None annotation.

🔧 Proposed fix
-def render_summarize_tab():
+def render_summarize_tab() -> None:
     """Render the summarize tab UI."""

Note: Other functions in this file also lack return type annotations (_render_no_videos_message, _render_summary_results, _render_chapter_summaries). Consider adding -> None to these as well for consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/tabs/summarize_tab.py` around lines 55 - 75, The function
render_summarize_tab is missing an explicit return type annotation; update its
signature to include "-> None" to reflect its implicit None return and maintain
typing consistency (modify the def render_summarize_tab(...) signature). Also
audit the related UI helper functions referenced in this
file—_render_no_videos_message, _render_summary_results, and
_render_chapter_summaries—and add "-> None" to their signatures as well so all
UI-rendering functions are fully typed.

Loading