{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Qwen3-ASR Amharic Curated Demo\n", "\n", "Run each cell in order. The final cell creates a temporary public Gradio link. Keep the notebook running while using the demo." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install -q -U qwen-asr gradio soundfile" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import torch\n", "from qwen_asr import Qwen3ASRModel\n", "\n", "MODEL_ID = \"b1n1yam/qwen3-asr-0.6b-amharic-gold-silver\"\n", "DEVICE = \"cuda:0\" if torch.cuda.is_available() else \"cpu\"\n", "DTYPE = torch.bfloat16 if torch.cuda.is_available() else torch.float32\n", "\n", "print(f\"Loading {MODEL_ID} on {DEVICE}\")\n", "model = Qwen3ASRModel.from_pretrained(\n", " MODEL_ID,\n", " dtype=DTYPE,\n", " device_map=DEVICE,\n", " attn_implementation=\"eager\",\n", " max_inference_batch_size=1,\n", " max_new_tokens=512,\n", ")\n", "print(\"Model ready\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "import soundfile as sf\n", "\n", "MAX_AUDIO_SECONDS = 60\n", "\n", "def transcribe(audio_path):\n", " if not audio_path:\n", " raise gr.Error(\"Record or upload an audio clip first.\")\n", " duration = sf.info(audio_path).duration\n", " if duration > MAX_AUDIO_SECONDS:\n", " raise gr.Error(f\"Please use audio shorter than {MAX_AUDIO_SECONDS} seconds.\")\n", " result = model.transcribe(audio=audio_path, language=None)\n", " return result[0].text\n", "\n", "with gr.Blocks(title=\"Qwen3 ASR Amharic Curated\") as demo:\n", " gr.Markdown(\"# Qwen3 ASR Amharic Curated\")\n", " with gr.Row():\n", " audio = gr.Audio(sources=[\"microphone\", \"upload\"], type=\"filepath\", label=\"Amharic audio\")\n", " transcript = gr.Textbox(label=\"Transcript\", lines=10, buttons=[\"copy\"])\n", " button = gr.Button(\"Transcribe\", variant=\"primary\")\n", " button.click(transcribe, inputs=audio, outputs=transcript, concurrency_limit=1)\n", "\n", "demo.queue(default_concurrency_limit=1).launch(share=True, debug=True)" ] } ] }