Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,10 @@ import ffmpeg
|
|
9 |
import time
|
10 |
import json
|
11 |
import psutil
|
12 |
-
from fuzzywuzzy import fuzz # Added for fuzzy matching
|
13 |
|
14 |
st.set_page_config(layout="wide")
|
15 |
|
16 |
-
# CSS Styling
|
17 |
st.markdown("""
|
18 |
<style>
|
19 |
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
|
@@ -263,7 +262,7 @@ footer {
|
|
263 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
264 |
""", unsafe_allow_html=True)
|
265 |
|
266 |
-
# Function Definitions
|
267 |
def format_time(seconds):
|
268 |
minutes = int(seconds // 60)
|
269 |
secs = int(seconds % 60)
|
@@ -590,52 +589,38 @@ def main():
|
|
590 |
st.session_state['show_timeframe'] = st.checkbox("Show timeframe in transcript", value=st.session_state['show_timeframe'])
|
591 |
st.markdown("### Search Subtitles")
|
592 |
search_query = st.text_input("Search subtitles...", value=st.session_state['search_query'], key="search_input")
|
593 |
-
st.session_state['search_query'] = search_query.lower().strip()
|
594 |
|
595 |
-
# Primary Transcript with
|
596 |
st.markdown(f"### {st.session_state['language']} Transcript")
|
597 |
primary_matches = 0
|
598 |
for text, start, end in st.session_state['primary_transcript']:
|
599 |
-
display_text = text.lower()
|
600 |
-
|
601 |
-
if not search_query:
|
602 |
-
match = True
|
603 |
-
elif len(search_query) < 3: # Exact match for very short queries
|
604 |
-
match = search_query in display_text
|
605 |
-
else: # Fuzzy matching for longer queries
|
606 |
-
match = fuzz.partial_ratio(search_query, display_text) >= 70
|
607 |
-
if match:
|
608 |
primary_matches += 1
|
609 |
label = f"[{format_time(start)} - {format_time(end)}] {text}" if st.session_state['show_timeframe'] else text
|
610 |
if st.button(label, key=f"primary_{start}"):
|
611 |
st.session_state['current_time'] = start
|
612 |
st.rerun()
|
613 |
-
if primary_matches == 0 and search_query:
|
614 |
st.info("No matches found in primary transcript for the search query.")
|
615 |
|
616 |
-
# English Transcript with
|
617 |
if st.session_state['english_transcript']:
|
618 |
st.markdown("### English Translation")
|
619 |
english_matches = 0
|
620 |
for text, start, end in st.session_state['english_transcript']:
|
621 |
-
display_text = text.lower()
|
622 |
-
|
623 |
-
if not search_query:
|
624 |
-
match = True
|
625 |
-
elif len(search_query) < 3: # Exact match for very short queries
|
626 |
-
match = search_query in display_text
|
627 |
-
else: # Fuzzy matching for longer queries
|
628 |
-
match = fuzz.partial_ratio(search_query, display_text) >= 70
|
629 |
-
if match:
|
630 |
english_matches += 1
|
631 |
label = f"[{format_time(start)} - {format_time(end)}] {text}" if st.session_state['show_timeframe'] else text
|
632 |
if st.button(label, key=f"english_{start}"):
|
633 |
st.session_state['current_time'] = start
|
634 |
st.rerun()
|
635 |
-
if english_matches == 0 and search_query:
|
636 |
st.info("No matches found in English transcript for the search query.")
|
637 |
|
638 |
-
# Summary Generation
|
639 |
if (st.session_state['language_code'] == 'en' or st.session_state['translate_to_english']) and not st.session_state['summary_generated']:
|
640 |
if st.button("Generate Summary"):
|
641 |
with st.spinner("Generating summary..."):
|
@@ -651,7 +636,7 @@ def main():
|
|
651 |
st.markdown("### Summary")
|
652 |
st.write(st.session_state['english_summary'])
|
653 |
|
654 |
-
# Download Subtitles
|
655 |
st.markdown("### Download Subtitles")
|
656 |
include_timeframe = st.checkbox("Include timeframe in subtitles", value=True)
|
657 |
transcript_to_download = st.session_state['primary_transcript'] or st.session_state['english_transcript']
|
@@ -659,7 +644,7 @@ def main():
|
|
659 |
srt_content = generate_srt(transcript_to_download, include_timeframe)
|
660 |
st.download_button(label="Download Subtitles (SRT)", data=srt_content, file_name="subtitles.srt", mime="text/plain")
|
661 |
|
662 |
-
# Edit Subtitles
|
663 |
st.markdown("### Edit Subtitles")
|
664 |
transcript_to_edit = st.session_state['primary_transcript'] or st.session_state['english_transcript']
|
665 |
if transcript_to_edit and st.button("Delete Subtitles"):
|
|
|
9 |
import time
|
10 |
import json
|
11 |
import psutil
|
|
|
12 |
|
13 |
st.set_page_config(layout="wide")
|
14 |
|
15 |
+
# CSS Styling (unchanged)
|
16 |
st.markdown("""
|
17 |
<style>
|
18 |
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
|
|
|
262 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
263 |
""", unsafe_allow_html=True)
|
264 |
|
265 |
+
# Function Definitions (unchanged)
|
266 |
def format_time(seconds):
|
267 |
minutes = int(seconds // 60)
|
268 |
secs = int(seconds % 60)
|
|
|
589 |
st.session_state['show_timeframe'] = st.checkbox("Show timeframe in transcript", value=st.session_state['show_timeframe'])
|
590 |
st.markdown("### Search Subtitles")
|
591 |
search_query = st.text_input("Search subtitles...", value=st.session_state['search_query'], key="search_input")
|
592 |
+
st.session_state['search_query'] = search_query.lower().strip() # Normalize query
|
593 |
|
594 |
+
# Primary Transcript with Fixed Search
|
595 |
st.markdown(f"### {st.session_state['language']} Transcript")
|
596 |
primary_matches = 0
|
597 |
for text, start, end in st.session_state['primary_transcript']:
|
598 |
+
display_text = text.lower() # Case-insensitive comparison
|
599 |
+
if not st.session_state['search_query'] or st.session_state['search_query'] in display_text:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
primary_matches += 1
|
601 |
label = f"[{format_time(start)} - {format_time(end)}] {text}" if st.session_state['show_timeframe'] else text
|
602 |
if st.button(label, key=f"primary_{start}"):
|
603 |
st.session_state['current_time'] = start
|
604 |
st.rerun()
|
605 |
+
if primary_matches == 0 and st.session_state['search_query']:
|
606 |
st.info("No matches found in primary transcript for the search query.")
|
607 |
|
608 |
+
# English Transcript with Fixed Search
|
609 |
if st.session_state['english_transcript']:
|
610 |
st.markdown("### English Translation")
|
611 |
english_matches = 0
|
612 |
for text, start, end in st.session_state['english_transcript']:
|
613 |
+
display_text = text.lower() # Case-insensitive comparison
|
614 |
+
if not st.session_state['search_query'] or st.session_state['search_query'] in display_text:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
615 |
english_matches += 1
|
616 |
label = f"[{format_time(start)} - {format_time(end)}] {text}" if st.session_state['show_timeframe'] else text
|
617 |
if st.button(label, key=f"english_{start}"):
|
618 |
st.session_state['current_time'] = start
|
619 |
st.rerun()
|
620 |
+
if english_matches == 0 and st.session_state['search_query']:
|
621 |
st.info("No matches found in English transcript for the search query.")
|
622 |
|
623 |
+
# Summary Generation (unchanged)
|
624 |
if (st.session_state['language_code'] == 'en' or st.session_state['translate_to_english']) and not st.session_state['summary_generated']:
|
625 |
if st.button("Generate Summary"):
|
626 |
with st.spinner("Generating summary..."):
|
|
|
636 |
st.markdown("### Summary")
|
637 |
st.write(st.session_state['english_summary'])
|
638 |
|
639 |
+
# Download Subtitles (unchanged)
|
640 |
st.markdown("### Download Subtitles")
|
641 |
include_timeframe = st.checkbox("Include timeframe in subtitles", value=True)
|
642 |
transcript_to_download = st.session_state['primary_transcript'] or st.session_state['english_transcript']
|
|
|
644 |
srt_content = generate_srt(transcript_to_download, include_timeframe)
|
645 |
st.download_button(label="Download Subtitles (SRT)", data=srt_content, file_name="subtitles.srt", mime="text/plain")
|
646 |
|
647 |
+
# Edit Subtitles (unchanged)
|
648 |
st.markdown("### Edit Subtitles")
|
649 |
transcript_to_edit = st.session_state['primary_transcript'] or st.session_state['english_transcript']
|
650 |
if transcript_to_edit and st.button("Delete Subtitles"):
|