mirror of
https://github.com/tcsenpai/youlama.git
synced 2025-06-07 03:35:41 +00:00
added po_token support at runtime
This commit is contained in:
parent
374924189f
commit
d2cebf8b02
@ -3,4 +3,5 @@ OLLAMA_MODEL=llama3.1:8b
|
|||||||
YOUTUBE_API_KEY=your_youtube_api_key
|
YOUTUBE_API_KEY=your_youtube_api_key
|
||||||
WHISPER_URL=http://localhost:8000/
|
WHISPER_URL=http://localhost:8000/
|
||||||
WHISPER_MODEL=Systran/faster-whisper-large-v3
|
WHISPER_MODEL=Systran/faster-whisper-large-v3
|
||||||
PASTEBIN_API_KEY=your_pastebin_api_key
|
PASTEBIN_API_KEY=your_pastebin_api_key
|
||||||
|
USE_PO_TOKEN=true
|
62
src/main.py
62
src/main.py
@ -252,7 +252,12 @@ def get_ollama_models(ollama_url):
|
|||||||
|
|
||||||
|
|
||||||
def summarize_video(
|
def summarize_video(
|
||||||
video_url, model, ollama_url, fallback_to_whisper=True, force_whisper=False
|
video_url,
|
||||||
|
model,
|
||||||
|
ollama_url,
|
||||||
|
fallback_to_whisper=True,
|
||||||
|
force_whisper=False,
|
||||||
|
use_po_token=None,
|
||||||
):
|
):
|
||||||
video_id = None
|
video_id = None
|
||||||
# Get the video id from the url if it's a valid youtube or invidious or any other url that contains a video id
|
# Get the video id from the url if it's a valid youtube or invidious or any other url that contains a video id
|
||||||
@ -284,7 +289,7 @@ def summarize_video(
|
|||||||
show_warning("Unable to fetch transcript. Trying to download audio...")
|
show_warning("Unable to fetch transcript. Trying to download audio...")
|
||||||
try:
|
try:
|
||||||
print("Downloading audio...")
|
print("Downloading audio...")
|
||||||
download_audio(video_url)
|
download_audio(video_url, use_po_token=use_po_token)
|
||||||
show_info("Audio downloaded successfully!")
|
show_info("Audio downloaded successfully!")
|
||||||
show_warning("Starting transcription...it might take a while...")
|
show_warning("Starting transcription...it might take a while...")
|
||||||
transcript = transcribe("downloads/output.m4a")
|
transcript = transcribe("downloads/output.m4a")
|
||||||
@ -320,7 +325,12 @@ def summarize_video(
|
|||||||
|
|
||||||
|
|
||||||
def fix_transcript(
|
def fix_transcript(
|
||||||
video_url, model, ollama_url, fallback_to_whisper=True, force_whisper=False
|
video_url,
|
||||||
|
model,
|
||||||
|
ollama_url,
|
||||||
|
fallback_to_whisper=True,
|
||||||
|
force_whisper=False,
|
||||||
|
use_po_token=None,
|
||||||
):
|
):
|
||||||
video_id = None
|
video_id = None
|
||||||
# Get the video id from the url if it's a valid youtube or invidious or any other url that contains a video id
|
# Get the video id from the url if it's a valid youtube or invidious or any other url that contains a video id
|
||||||
@ -352,7 +362,7 @@ def fix_transcript(
|
|||||||
show_warning("Unable to fetch transcript. Trying to download audio...")
|
show_warning("Unable to fetch transcript. Trying to download audio...")
|
||||||
try:
|
try:
|
||||||
print("Downloading audio...")
|
print("Downloading audio...")
|
||||||
download_audio(video_url)
|
download_audio(video_url, use_po_token=use_po_token)
|
||||||
show_info("Audio downloaded successfully!")
|
show_info("Audio downloaded successfully!")
|
||||||
show_warning("Starting transcription...it might take a while...")
|
show_warning("Starting transcription...it might take a while...")
|
||||||
transcript = transcribe("downloads/output.m4a")
|
transcript = transcribe("downloads/output.m4a")
|
||||||
@ -437,31 +447,27 @@ def main():
|
|||||||
read_button = st.button("📖 Read", use_container_width=True)
|
read_button = st.button("📖 Read", use_container_width=True)
|
||||||
|
|
||||||
# Advanced settings in collapsible sections
|
# Advanced settings in collapsible sections
|
||||||
with st.expander("⚙️ Advanced Settings"):
|
with st.expander("⚙️ Advanced Settings", expanded=False):
|
||||||
# Whisper Settings
|
col1, col2 = st.columns(2)
|
||||||
st.subheader("🎤 Whisper Settings")
|
|
||||||
default_whisper_url = os.getenv("WHISPER_URL")
|
|
||||||
whisper_url = st.text_input(
|
|
||||||
"Whisper URL",
|
|
||||||
value=default_whisper_url,
|
|
||||||
placeholder="Enter Whisper URL",
|
|
||||||
)
|
|
||||||
if not whisper_url:
|
|
||||||
whisper_url = default_whisper_url
|
|
||||||
|
|
||||||
whisper_model = os.getenv("WHISPER_MODEL")
|
with col1:
|
||||||
if not whisper_model:
|
fallback_to_whisper = st.checkbox(
|
||||||
whisper_model = "Systran/faster-whisper-large-v3"
|
"Fallback to Whisper",
|
||||||
st.caption(f"Current model: {whisper_model}")
|
value=True,
|
||||||
|
help="If no transcript is available, try to generate one using Whisper",
|
||||||
|
)
|
||||||
|
force_whisper = st.checkbox(
|
||||||
|
"Force Whisper",
|
||||||
|
value=False,
|
||||||
|
help="Always use Whisper for transcription",
|
||||||
|
)
|
||||||
|
|
||||||
st.markdown("<br>", unsafe_allow_html=True) # Add some spacing
|
with col2:
|
||||||
|
use_po_token = st.checkbox(
|
||||||
# Whisper Options
|
"Use PO Token",
|
||||||
adv_col1, adv_col2 = st.columns(2)
|
value=get_po_token_setting(), # Default from environment
|
||||||
with adv_col1:
|
help="Use PO token for YouTube authentication (helps bypass restrictions)",
|
||||||
force_whisper = st.checkbox("Force Whisper", value=False)
|
)
|
||||||
with adv_col2:
|
|
||||||
fallback_to_whisper = st.checkbox("Fallback to Whisper", value=True)
|
|
||||||
|
|
||||||
if (summarize_button or read_button) and video_url:
|
if (summarize_button or read_button) and video_url:
|
||||||
if read_button:
|
if read_button:
|
||||||
@ -472,6 +478,7 @@ def main():
|
|||||||
ollama_url,
|
ollama_url,
|
||||||
fallback_to_whisper=fallback_to_whisper,
|
fallback_to_whisper=fallback_to_whisper,
|
||||||
force_whisper=force_whisper,
|
force_whisper=force_whisper,
|
||||||
|
use_po_token=use_po_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Display results
|
# Display results
|
||||||
@ -502,6 +509,7 @@ def main():
|
|||||||
ollama_url,
|
ollama_url,
|
||||||
fallback_to_whisper=fallback_to_whisper,
|
fallback_to_whisper=fallback_to_whisper,
|
||||||
force_whisper=force_whisper,
|
force_whisper=force_whisper,
|
||||||
|
use_po_token=use_po_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Video Information
|
# Video Information
|
||||||
|
@ -1,20 +1,29 @@
|
|||||||
from pytubefix import YouTube
|
from pytubefix import YouTube
|
||||||
from pytubefix.cli import on_progress
|
from pytubefix.cli import on_progress
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
|
||||||
"""e.g.
|
load_dotenv()
|
||||||
https://www.youtube.com/watch?v=vwTDiLH6mqg
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def download_audio(url):
|
def get_po_token_setting():
|
||||||
|
env_setting = os.getenv("USE_PO_TOKEN", "true").lower() == "true"
|
||||||
|
return env_setting
|
||||||
|
|
||||||
|
|
||||||
|
def download_audio(url, use_po_token=None):
|
||||||
try:
|
try:
|
||||||
|
# If use_po_token is not provided, use the environment variable
|
||||||
|
if use_po_token is None:
|
||||||
|
use_po_token = get_po_token_setting()
|
||||||
|
|
||||||
# Create YouTube object with bot detection bypass
|
# Create YouTube object with bot detection bypass
|
||||||
yt = YouTube(
|
yt = YouTube(
|
||||||
url,
|
url,
|
||||||
on_progress_callback=on_progress,
|
on_progress_callback=on_progress,
|
||||||
use_oauth=True,
|
use_oauth=True,
|
||||||
allow_oauth_cache=True,
|
allow_oauth_cache=True,
|
||||||
use_po_token=True, # Add this to bypass bot detection
|
use_po_token=use_po_token, # Now configurable
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get audio stream
|
# Get audio stream
|
||||||
|
Loading…
x
Reference in New Issue
Block a user