Skip to content

Commit

Permalink
feat: add cache for caption and retry attempt for caption fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
sean1832 committed Mar 26, 2023
1 parent a0e2621 commit 5763634
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/SumGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
if st.button("🚀 Run", disabled=exceeded):
start_time = time.time()
st.cache_data.clear()
util.clear_cache('summary')
API_KEY = st.session_state['OPENAI_API_KEY']
if not API_KEY and not GPT.misc.validate_api_key(API_KEY):
st.error("❌ Please enter a valid [OpenAI API key](https://beta.openai.com/account/api-keys).")
Expand Down
20 changes: 12 additions & 8 deletions src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ def _extract_xml_caption(xml: str, is_auto_lang: bool) -> str:
text_content = text
return text_content.strip()


@st.cache_data(show_spinner=False)
def _get_caption(url: str, lang_code: str | List[str] = 'a.en') -> str:
"""Extracts the transcript from a YouTube video."""
attempt = 3
yt = YouTube(url)
caption = None
selected_lang = None
Expand All @@ -57,15 +58,18 @@ def _get_caption(url: str, lang_code: str | List[str] = 'a.en') -> str:
except KeyError:
continue # try next language

info_display = st.empty()

if caption is None:
source_captions = yt.captions
try:
if source_captions == {}:
st.error(f'❌ No captions found in this video. Please try another one.')
except KeyError:
st.error(f'❌ Caption language currently not supported.\n\n'
f'{source_captions}\n\n'
f'Please [report this issue on Here](https://github.com/sean1832/SumGPT/issues)')
for i in range(attempt):
try:
if source_captions == {}:
info_display.error(f'❌ No captions found in this video. Please try another one.')
except KeyError:
info_display.error(f'❌ Caption language currently not supported.\n\n'
f'{source_captions}\n\n'
f'Please [report this issue on Here](https://github.com/sean1832/SumGPT/issues)')
st.stop()

else:
Expand Down

0 comments on commit 5763634

Please sign in to comment.