-
Notifications
You must be signed in to change notification settings - Fork 0
improvement: reduce complexity of the Summarize tab #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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} | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add explicit return type and use specific type for The function is missing a return type annotation and uses a generic 🔧 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 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add explicit return type and use specific type for The function is missing a return type annotation and uses a generic 🔧 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 |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use specific return type annotation. The function uses a generic 🔧 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 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use specific return type annotation. The function uses a generic 🔧 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 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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 --strictRepository: 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 mypyRepository: varit05/Streaming-Video-RAG Length of output: 117 🏁 Script executed: python -m mypy ui/tabs/summarize_tab.py --strict 2>&1 | head -50Repository: 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 2Repository: varit05/Streaming-Video-RAG Length of output: 1239 Add explicit return type annotation to 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 🔧 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 ( 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use specific type annotations instead of generic types.
The function uses generic
listanddicttypes instead of specific type annotations. As per coding guidelines, all functions must be fully typed.🔧 Proposed fix with specific type annotations
🤖 Prompt for AI Agents