Aryan2301/YouTube_RAG_Intelligence
0
1import streamlit as st2 3from utils.formatting import format_time4 5from services.youtube_service import build_youtube_timestamp_url6 7 8def render_transcript_ui():9 10 st.subheader("📄 Transcript Explorer")11 12 transcript_text = st.session_state.transcript_text13 transcript_segments = st.session_state.transcript_segments14 video_id = st.session_state.video_id15 16 if not transcript_segments or not transcript_text:17 st.warning("⚠️ No transcript data available for this video.")18 return19 20 col_mode, col_search = st.columns([1, 2])21 22 view_mode = col_mode.radio(23 "View Mode",24 ["Plain Text", "Timestamped Segments"],25 horizontal=True,26 )27 28 search_query = col_search.text_input(29 "🔍 Search Transcript",30 placeholder="Enter keyword…",31 )32 33 st.divider()34 35 if view_mode == "Plain Text":36 37 display_text = transcript_text38 39 if search_query:40 41 matched = [42 seg["text"]43 for seg in transcript_segments44 if search_query.lower() in seg["text"].lower()45 ]46 47 display_text = (48 "\n\n".join(matched)49 if matched50 else "No matches found."51 )52 53 st.text_area(54 "Transcript",55 display_text,56 height=450,57 disabled=True,58 )59 60 else:61 62 filtered = transcript_segments63 64 if search_query:65 filtered = [66 seg67 for seg in transcript_segments68 if search_query.lower() in seg["text"].lower()69 ]70 71 if not filtered:72 st.info("No matching segments found.")73 74 else:75 76 st.caption(f"{len(filtered):,} segments found")77 78 for seg in filtered:79 80 timestamp = format_time(seg["start"])81 82 yt_url = build_youtube_timestamp_url(83 video_id=video_id,84 seconds=int(seg["start"]),85 )86 87 c1, c2 = st.columns([1, 7])88 89 c1.link_button(90 timestamp,91 yt_url,92 use_container_width=True,93 )94 95 c2.write(seg["text"])96 97 st.divider()98 99 col1, col2 = st.columns(2)100 101 col1.download_button(102 label="⬇️ Download (.txt)",103 data=transcript_text,104 file_name="transcript.txt",105 mime="text/plain",106 use_container_width=True,107 )108 109 col2.download_button(110 label="⬇️ Download (.md)",111 data="# Transcript\n\n" + transcript_text,112 file_name="transcript.md",113 mime="text/markdown",114 use_container_width=True,115 )