{ "cells": [ { "cell_type": "code", "execution_count": 9, "metadata": { "output": { "id": 1352671522828979, "loadingStatus": "loaded" } }, "outputs": [], "source": [ "import torch\n", "from IPython.display import Audio, Video\n", "\n", "from sam_audio import SAMAudio, SAMAudioProcessor" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "output": { "id": 885916534002331, "loadingStatus": "loaded" } }, "outputs": [], "source": [ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", "model = SAMAudio.from_pretrained(\"facebook/sam-audio-large\").to(device).eval()\n", "processor = SAMAudioProcessor.from_pretrained(\"facebook/sam-audio-large\")" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "output": { "id": 1281362027072041, "loadingStatus": "loaded" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "video_file = \"assets/office.mp4\"\n", "Video(video_file, embed=True, width=640, height=360)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "inputs = processor(audios=[video_file], descriptions=[\"A man speaking\"]).to(device)\n", "with torch.inference_mode():\n", " result = model.separate(inputs)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Audio(result.target[0].cpu(), rate=processor.audio_sampling_rate)" ] } ], "metadata": { "fileHeader": "", "fileUid": "8f909f1e-e114-4e58-8c41-a7e2effd92ae", "isAdHoc": false, "kernelspec": { "display_name": "sam-audio", "language": "python", "name": "sam-audio" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.13" } }, "nbformat": 4, "nbformat_minor": 4 }