Skip to content

Chore/clean saving folder #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
import time
import gradio as gr
from pathlib import Path
import google.generativeai as genai
Expand All @@ -12,6 +13,10 @@
model = genai.GenerativeModel('models/gemini-1.5-flash')


# Create main output directories for segmented audios.
segment_folder = Path("segments/")
segment_folder.mkdir(exist_ok=True)

def process_audio(audio_file, should_summarize):
"""Process audio file: convert, segment, transcribe and optionally summarize"""
try:
Expand All @@ -23,16 +28,21 @@ def process_audio(audio_file, should_summarize):
output_wav_name = Path(audio_file.name).stem + '.wav'
output_wav_path = str(Path(input_path).parent / output_wav_name)

# Create output directories
segment_folder = Path("segments/")
segment_folder.mkdir(exist_ok=True)

# Process audio
print(f"Converting {input_path} to {output_wav_path}")
convert_mp4_to_wav(input_path) # This should output to output_wav_path

# Create output dir based on current timestamp for converted audio.
current_time = time.strftime("%Y%m%d-%H%M")
current_time_segment_folder = segment_folder / current_time
os.makedirs(current_time_segment_folder, exist_ok=True)

# Create folder for segmented audios.
segment_audios_folder = current_time_segment_folder / output_wav_name
os.makedirs(segment_audios_folder, exist_ok=True)
Comment on lines +38 to +42
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the rest of the codebase using pathlib.Path, you could replace os.makedirs(...) with current_time_segment_folder.mkdir(exist_ok=True, parents=true).

Suggested change
os.makedirs(current_time_segment_folder, exist_ok=True)
# Create folder for segmented audios.
segment_audios_folder = current_time_segment_folder / output_wav_name
os.makedirs(segment_audios_folder, exist_ok=True)
current_time_segment_folder.mkdir(exist_ok=True, parents=True)
# Create folder for segmented audios.
segment_audios_folder = current_time_segment_folder / output_wav_name
segment_audios_folder.mkdir(exist_ok=True, parents=True)

Copilot uses AI. Check for mistakes.


print(f"Splitting audio from {output_wav_path}")
split_audio(output_wav_path, str(segment_folder))
split_audio(output_wav_path, str(segment_audios_folder))

# Transcribe
print("Transcribing segments...")
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
json
python-docx
tqdm
gradio
csv
textwrap
BeautifulSoup4
markdown
pandas
Expand Down