Skip to content

Commit

Permalink
test adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
neonwatty committed Jul 17, 2024
1 parent 110b5ee commit 94a4dbd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.test
pip install -r requirements.txt
pip install -r requirements.streamlit
- name: Run pytest
run: |
PYTHONPATH=. python3.10 -m pytest tests/test_streamlit.py
1 change: 0 additions & 1 deletion bleep_that_sht/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def bleep_replace(
bleep_words: list,
timestamped_transcript: dict,
) -> None:

# # extract and save audio from original video
# extract_audio(local_file_path=og_video_path, audio_filepath=og_audio_path)

Expand Down
34 changes: 20 additions & 14 deletions bleep_that_sht/gradio_app_url_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

try:
HF_TOKEN = os.environ.get("HF_TOKEN")
except:
except: # noqa E722
pass


Expand All @@ -40,7 +40,13 @@
value="treetz, ice, cream, chocolate, syrup, cookie, hooked, threats, treats, trees",
)
with gr.Column(scale=3):
model_selection = gr.Dropdown(choices=avaliable_models, value="base", label="whisper model (base only in HF space)", info="whisper model selection", interactive=False)
model_selection = gr.Dropdown(
choices=avaliable_models,
value="base",
label="whisper model (base only in HF space)",
info="whisper model selection",
interactive=False,
)
with gr.Column(scale=4):
just_transcribe_button = gr.Button("Just Transcribe", variant="primary")
transcribe_and_bleep_button = gr.Button("Transcribe & Bleep", variant="primary")
Expand All @@ -59,7 +65,7 @@
width="50vw",
height="50vw",
)

bleep_video = gr.Video(
visible=False,
show_download_button=True,
Expand All @@ -80,7 +86,7 @@ def just_transcribe(url_input, model_selection):
byte_file = io.BytesIO(filename.read())
with open(temporary_video_location, "wb") as out:
out.write(byte_file.read())

new_og_video = gr.Video(
value=temporary_video_location,
visible=True,
Expand All @@ -91,7 +97,7 @@ def just_transcribe(url_input, model_selection):
width="50vw",
height="50vw",
)

new_bleep_video = gr.Video(
visible=False,
show_download_button=True,
Expand All @@ -101,17 +107,17 @@ def just_transcribe(url_input, model_selection):
width="50vw",
height="50vw",
)



extract_audio(temporary_video_location, temporary_audio_location)
transcript, timestamped_transcript = transcribe(local_file_path=temporary_audio_location, model=model_selection)

return new_og_video, new_bleep_video, transcript


@transcribe_and_bleep_button.click(inputs=[url_input, model_selection, bleep_words], outputs=[og_video, bleep_video, transcript_output])

@transcribe_and_bleep_button.click(
inputs=[url_input, model_selection, bleep_words], outputs=[og_video, bleep_video, transcript_output]
)
def transcribe_and_bleep(url_input, model_selection, bleep_words):
if len(bleep_words) > 0:
if len(bleep_words) > 0:
temporary_video_location = tmpdirname + "/original_" + str(uuid.uuid4()) + ".mp4"
temporary_audio_location = temporary_video_location.replace("mp4", "mp3")

Expand All @@ -120,7 +126,7 @@ def transcribe_and_bleep(url_input, model_selection, bleep_words):
byte_file = io.BytesIO(filename.read())
with open(temporary_video_location, "wb") as out:
out.write(byte_file.read())

new_og_video = gr.Video(
value=temporary_video_location,
visible=True,
Expand All @@ -131,7 +137,7 @@ def transcribe_and_bleep(url_input, model_selection, bleep_words):
width="50vw",
height="50vw",
)

extract_audio(temporary_video_location, temporary_audio_location)
transcript, timestamped_transcript = transcribe(local_file_path=temporary_audio_location, model=model_selection)

Expand Down Expand Up @@ -159,7 +165,7 @@ def transcribe_and_bleep(url_input, model_selection, bleep_words):
width="50vw",
height="50vw",
)

return new_og_video, new_bleep_video, transcript
else:
gr.Warning("bleep words empty!", duration=3)
Expand Down
6 changes: 3 additions & 3 deletions bleep_that_sht/yt_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def download_video(url: str, savepath: str, my_proxies: dict = {}) -> None:
print("Downloading video from youtube...")
if is_valid_youtube_url(url):
ydl_opts = {
'format': 'bestvideo[height<=720]+bestaudio/best',
'merge_output_format': 'mp4',
'outtmpl': savepath,
"format": "bestvideo[height<=720]+bestaudio/best",
"merge_output_format": "mp4",
"outtmpl": savepath,
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
Expand Down
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

cwd = os.getcwd()
CONTAINER_NAME = "bleep_that_sht"
STREAMLIT_UPLOAD_FILE = "bleep_that_sht/app_video_upload.py"
STREAMLIT_DOWNLOAD_FILE = "bleep_that_sht/app_url_download.py"
STREAMLIT_UPLOAD_FILE = "bleep_that_sht/streamlit_app_video_upload.py"
STREAMLIT_DOWNLOAD_FILE = "bleep_that_sht/streamlit_app_url_download.py"

0 comments on commit 94a4dbd

Please sign in to comment.