{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "kPCLdTfJyktF" }, "outputs": [], "source": [ "import torch\n", "\n", "import gradio as gr\n", "import pytube as pt\n", "from transformers import pipeline\n", "\n", "asr = pipeline(\n", " task=\"automatic-speech-recognition\",\n", " model=\"Yasaman/whisper_fa\",\n", " chunk_length_s=30,\n", " device=\"cpu\",\n", ")\n", "\n", "summarizer = pipeline(\n", " \"summarization\",\n", " model=\"alireza7/PEGASUS-persian-base-PN-summary\",\n", ")\n", "\n", "translator = pipeline(\n", " \"translation\", \n", " model=\"Helsinki-NLP/opus-mt-iir-en\")\n", "\n", "def transcribe(microphone, file_upload):\n", " warn_output = \"\"\n", " if (microphone is not None) and (file_upload is not None):\n", " warn_output = (\n", " \"WARNING: You've uploaded an audio file and used the microphone. \"\n", " \"The recorded file from the microphone will be used and the uploaded audio will be discarded.\\n\"\n", " )\n", "\n", " elif (microphone is None) and (file_upload is None):\n", " return \"ERROR: You have to either use the microphone or upload an audio file\"\n", "\n", " file = microphone if microphone is not None else file_upload\n", "\n", " text = asr(file)[\"text\"]\n", "\n", " translate = translator(text)\n", " translate = translate[0][\"translation_text\"]\n", "\n", " return warn_output + text, translate\n", "\n", "def _return_yt_html_embed(yt_url):\n", " video_id = yt_url.split(\"?v=\")[-1]\n", " HTML_str = (\n", " f'