added rephrase as an option

This commit is contained in:
tcsenpai 2024-12-25 18:38:30 +01:00
parent baa906c11a
commit f64b409805

View File

@ -177,7 +177,7 @@ def show_error(message):
def show_info(message):
update_header(" " + message)
update_header("<EFBFBD><EFBFBD><EFBFBD> " + message)
def update_header(message):
@ -352,7 +352,7 @@ def main():
# Video URL input section
with st.container():
url_col, button_col = st.columns([4, 1])
url_col, button_col1, button_col2 = st.columns([3, 1, 1])
with url_col:
video_url = st.text_input(
@ -360,9 +360,12 @@ def main():
placeholder="https://www.youtube.com/watch?v=...",
)
with button_col:
with button_col1:
summarize_button = st.button("🚀 Summarize", use_container_width=True)
with button_col2:
rephrase_button = st.button("🔄 Rephrase Only", use_container_width=True)
# Advanced settings in collapsible sections
with st.expander("⚙️ Advanced Settings"):
# Whisper Settings
@ -390,7 +393,44 @@ def main():
with adv_col2:
fallback_to_whisper = st.checkbox("Fallback to Whisper", value=True)
if summarize_button and video_url:
if (summarize_button or rephrase_button) and video_url:
video_id = None
if "v=" in video_url:
video_id = video_url.split("v=")[-1]
elif "youtu.be/" in video_url:
video_id = video_url.split("youtu.be/")[-1]
video_id = video_id.split("&")[0]
st.write(f"Video ID: {video_id}")
with st.spinner("Fetching transcript..."):
transcript = get_transcript(video_id)
if transcript:
show_info("Transcript fetched successfully!")
if rephrase_button:
# Only rephrase the transcript
show_warning("Starting rephrasing, this might take a while...")
with st.spinner("Rephrasing transcript..."):
ollama_client = OllamaClient(ollama_url, selected_model)
prompt = f"Rephrase the following transcript to make it more readable and well-formatted, keeping the main content intact:\n\n{transcript}"
rephrased = ollama_client.generate(prompt)
video_info = get_video_info(video_id)
# Display results
st.subheader("📺 Video Information")
info_col1, info_col2 = st.columns(2)
with info_col1:
st.write(f"**Title:** {video_info['title']}")
with info_col2:
st.write(f"**Channel:** {video_info['channel']}")
st.subheader("📝 Rephrased Transcript")
st.markdown(rephrased)
elif summarize_button:
# Continue with existing summarize functionality
summary = summarize_video(
video_url,
selected_model,
@ -422,8 +462,8 @@ def main():
with st.spinner("Rephrasing transcript..."):
ollama_client = OllamaClient(ollama_url, selected_model)
prompt = f"Rephrase the following transcript to make it more readable and well-formatted, keeping the main content intact:\n\n{summary['transcript']}"
st.session_state.rephrased_transcript = ollama_client.generate(
prompt
st.session_state.rephrased_transcript = (
ollama_client.generate(prompt)
)
if st.button("📋 Share"):