From 83779faf461ee478c416dd96d4f6030e223cd4b1 Mon Sep 17 00:00:00 2001 From: Eric Meehan Date: Tue, 25 Mar 2025 22:50:55 -0400 Subject: [PATCH] Execute application with Gitea Actions --- .env_example | 1 + .gitea/workflows/execute.yaml | 22 ++++++++++++++++++++++ app.py | 19 ++++++++++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 .gitea/workflows/execute.yaml diff --git a/.env_example b/.env_example index 7447381..25e7d50 100644 --- a/.env_example +++ b/.env_example @@ -3,3 +3,4 @@ OPENAI_BASE_URL = OPENAI_RESPONSES_PROMPT = SEGMENT_DURATION = TMP_AUDIO_PATH = +TMP_VIDEO_PATH = diff --git a/.gitea/workflows/execute.yaml b/.gitea/workflows/execute.yaml new file mode 100644 index 0000000..cd4cfda --- /dev/null +++ b/.gitea/workflows/execute.yaml @@ -0,0 +1,22 @@ +name: Execute video summary bot +on: + workflow_dispatch: + inputs: + video-url: + description: "URL for the video to be analyzed" + required: true +jobs: + Python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run applicaiton + run: python app.py diff --git a/app.py b/app.py index 4676a2d..8f60520 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,3 @@ -import argparse import os from dotenv import load_dotenv @@ -14,12 +13,24 @@ def main(args): openai_client, transcribe_audio( openai_client, - get_audio_from_video(args.video_file_path) + get_audio_from_video( + get_video_from_url() + ) ) ) -def get_audio_from_video(video_file_path): +def get_video_from_url(): + video_file_url = os.getenv('INPUT_VIDEO_URL') + video_file_path = os.getenv('TMP_VIDEO_PATH' , '/tmp/video_summary_bot_tmp_video.mp4') + request = requests.get(video_file_url) + with open(video_file_path, 'wb') as f: + for chunk in requests.get(video_file_url).iter_content(chunk_size=255): + if chunk: + f.write(chunk) + +def get_audio_from_video(): tmp_audio_path = os.getenv('TMP_AUDIO_PATH', '/tmp/video_summary_bot_tmp_audio.wav') + video_file_path = os.getenv('TMP_VIDEO_PATH') VideoFileClip(video_file_path).audio.write_audiofile(tmp_audio_path) return AudioSegment.from_wav(tmp_audio_path) @@ -44,6 +55,4 @@ def summarize_transcription(openai_client, transcription): if __name__ == '__main__': load_dotenv() - parser = argparse.ArgumentParser(description="Use AI models to summarize videos") - parser.add_argument('--video-file-path', type=str, help="Path to the video to be summarized") main(parser.parse_args())