Spaces:
Running
Running
File size: 2,101 Bytes
3b3660f |
1 |
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: audio_subtitle"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('files')\n", "!wget -q -O files/a.mp3 https://github.com/gradio-app/gradio/raw/main/demo/audio_subtitle/files/a.mp3\n", "!wget -q -O files/b.mp3 https://github.com/gradio-app/gradio/raw/main/demo/audio_subtitle/files/b.mp3\n", "!wget -q -O files/s1.srt https://github.com/gradio-app/gradio/raw/main/demo/audio_subtitle/files/s1.srt\n", "!wget -q -O files/s2.vtt https://github.com/gradio-app/gradio/raw/main/demo/audio_subtitle/files/s2.vtt"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import os\n", "\n", "a = os.path.join(os.path.abspath(''), \"files/a.mp3\")\n", "b = os.path.join(os.path.abspath(''), \"files/b.mp3\")\n", "s1 = os.path.join(os.path.abspath(''), \"files/s1.srt\")\n", "s2 = os.path.join(os.path.abspath(''), \"files/s2.vtt\")\n", "\n", "def add_subtitles_to_audio(audio, subtitles=None):\n", " if subtitles is None:\n", " return audio\n", " if subtitles is not None:\n", " return gr.Audio(label=\"Out\", value=audio, subtitles=subtitles.name)\n", "\n", "demo = gr.Interface(\n", " fn=add_subtitles_to_audio,\n", " inputs=[\n", " gr.Audio(label=\"In\", interactive=True),\n", " gr.File(label=\"Subtitle\", file_types=[\".srt\", \".vtt\"]),\n", " ],\n", " outputs=gr.Audio(label=\"Out\"),\n", " examples=[\n", " [a, s1],\n", " [b, s2],\n", " ],\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |