{ "cells": [ { "cell_type": "code", "execution_count": 29, "id": "5c7d8fe6-69ca-4f29-9046-0b0bc9f31911", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "99ee6b03c5154644998c23c837444e83", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(Button(button_style='success', description='Record', icon='microphone', style=ButtonStyle()), B…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2b3e4f24da8d4c198b5d15f0f3f7399d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import ipywidgets as widgets\n", "from IPython.display import display, clear_output\n", "from threading import Thread\n", "from queue import Queue\n", "import time\n", "\n", "messages = Queue()\n", "recordings = Queue()\n", "\n", "record_button = widgets.Button(\n", " description=\"Record\",\n", " disabled=False,\n", " button_style=\"success\",\n", " icon=\"microphone\"\n", ")\n", "\n", "stop_button = widgets.Button(\n", " description=\"Stop\",\n", " disabled=False,\n", " button_style=\"warning\",\n", " icon=\"stop\"\n", ")\n", "\n", "output = widgets.Output()\n", "\n", "def record_microphone():\n", " while not messages.empty():\n", " time.sleep(1) # Simulate recording\n", " recordings.put(\"Audio recorded.\") # Simulated recorded audio data\n", "\n", "def speech_recognition(output_widget):\n", " while not messages.empty():\n", " time.sleep(2) # Simulate transcription\n", " with output_widget:\n", " clear_output(wait=True)\n", " display(\"Transcription: Hello, how are you?\") # Simulated transcription result\n", "\n", "def start_recording(data):\n", " if not messages.empty():\n", " return # Recording already in progress\n", "\n", " messages.put(True)\n", " with output:\n", " clear_output(wait=True)\n", " display(\"Starting...\")\n", "\n", " record = Thread(target=record_microphone)\n", " record.start()\n", "\n", " transcribe = Thread(target=speech_recognition, args=(output,))\n", " transcribe.start()\n", "\n", "def stop_recording(data):\n", " if messages.empty():\n", " return # No recording in progress\n", "\n", " messages.get()\n", " with output:\n", " clear_output(wait=True)\n", " display(\"Stopped.\")\n", "\n", "record_button.on_click(start_recording)\n", "stop_button.on_click(stop_recording)\n", "\n", "display(widgets.HBox([record_button, stop_button]), output)\n" ] }, { "cell_type": "code", "execution_count": 30, "id": "bdcb9097-ab31-4dcc-9e2a-4e0818fceb3f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pyaudio in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (0.2.14)\n" ] } ], "source": [ "!python -m pip install pyaudio" ] }, { "cell_type": "code", "execution_count": 31, "id": "34112777-1845-4aff-80de-099ceed52f01", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'index': 0, 'structVersion': 2, 'name': 'Microsoft Sound Mapper - Input', 'hostApi': 0, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}\n", "{'index': 1, 'structVersion': 2, 'name': 'Microphone Array (Intel® Smart ', 'hostApi': 0, 'maxInputChannels': 4, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}\n", "{'index': 2, 'structVersion': 2, 'name': 'Microsoft Sound Mapper - Output', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}\n", "{'index': 3, 'structVersion': 2, 'name': 'Speakers (Realtek(R) Audio)', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}\n", "{'index': 4, 'structVersion': 2, 'name': 'Primary Sound Capture Driver', 'hostApi': 1, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.12, 'defaultLowOutputLatency': 0.0, 'defaultHighInputLatency': 0.24, 'defaultHighOutputLatency': 0.0, 'defaultSampleRate': 44100.0}\n", "{'index': 5, 'structVersion': 2, 'name': 'Microphone Array (Intel® Smart Sound Technology (Intel® SST))', 'hostApi': 1, 'maxInputChannels': 4, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.12, 'defaultLowOutputLatency': 0.0, 'defaultHighInputLatency': 0.24, 'defaultHighOutputLatency': 0.0, 'defaultSampleRate': 44100.0}\n", "{'index': 6, 'structVersion': 2, 'name': 'Primary Sound Driver', 'hostApi': 1, 'maxInputChannels': 0, 'maxOutputChannels': 8, 'defaultLowInputLatency': 0.0, 'defaultLowOutputLatency': 0.12, 'defaultHighInputLatency': 0.0, 'defaultHighOutputLatency': 0.24, 'defaultSampleRate': 44100.0}\n", "{'index': 7, 'structVersion': 2, 'name': 'Speakers (Realtek(R) Audio)', 'hostApi': 1, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.0, 'defaultLowOutputLatency': 0.12, 'defaultHighInputLatency': 0.0, 'defaultHighOutputLatency': 0.24, 'defaultSampleRate': 44100.0}\n", "{'index': 8, 'structVersion': 2, 'name': 'Speakers (Realtek(R) Audio)', 'hostApi': 2, 'maxInputChannels': 0, 'maxOutputChannels': 8, 'defaultLowInputLatency': 0.0, 'defaultLowOutputLatency': 0.003, 'defaultHighInputLatency': 0.0, 'defaultHighOutputLatency': 0.01, 'defaultSampleRate': 48000.0}\n", "{'index': 9, 'structVersion': 2, 'name': 'Microphone Array (Intel® Smart Sound Technology (Intel® SST))', 'hostApi': 2, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.002, 'defaultLowOutputLatency': 0.0, 'defaultHighInputLatency': 0.01, 'defaultHighOutputLatency': 0.0, 'defaultSampleRate': 48000.0}\n", "{'index': 10, 'structVersion': 2, 'name': 'Microphone Array 1 (Intel® Smart Sound Technology (Intel® SST) Microphone)', 'hostApi': 3, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 48000.0}\n", "{'index': 11, 'structVersion': 2, 'name': 'Microphone Array 2 (Intel® Smart Sound Technology (Intel® SST) Microphone)', 'hostApi': 3, 'maxInputChannels': 4, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 16000.0}\n", "{'index': 12, 'structVersion': 2, 'name': 'Microphone Array 3 (Intel® Smart Sound Technology (Intel® SST) Microphone)', 'hostApi': 3, 'maxInputChannels': 4, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 16000.0}\n", "{'index': 13, 'structVersion': 2, 'name': 'Stereo Mix (Realtek HD Audio Stereo input)', 'hostApi': 3, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 48000.0}\n", "{'index': 14, 'structVersion': 2, 'name': 'Headphones (Realtek HD Audio 2nd output with SST)', 'hostApi': 3, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 48000.0}\n", "{'index': 15, 'structVersion': 2, 'name': 'Speakers (Realtek HD Audio output with SST)', 'hostApi': 3, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 48000.0}\n", "{'index': 16, 'structVersion': 2, 'name': 'Microphone (Realtek HD Audio Mic input)', 'hostApi': 3, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.04, 'defaultHighOutputLatency': 0.04, 'defaultSampleRate': 44100.0}\n" ] } ], "source": [ "import pyaudio\n", "\n", "p = pyaudio.PyAudio()\n", "for i in range(p.get_device_count()):\n", " print(p.get_device_info_by_index(i))\n", "\n", "p.terminate()" ] }, { "cell_type": "code", "execution_count": 32, "id": "2e74dacf-1a91-4dfa-bf91-c64c72755d75", "metadata": {}, "outputs": [], "source": [ "import pyaudio\n", "from queue import Queue\n", "\n", "CHANNELS = 1\n", "FRAME_RATE = 16000\n", "RECORD_SECONDS = 20\n", "AUDIO_FORMAT = pyaudio.paInt16\n", "SAMPLE_SIZE = 2\n", "\n", "messages = Queue()\n", "recordings = Queue()\n", "\n", "def record_microphone(chunk=1024):\n", " p = pyaudio.PyAudio()\n", "\n", " stream = p.open(format=AUDIO_FORMAT,\n", " channels=CHANNELS,\n", " rate=FRAME_RATE,\n", " input=True,\n", " input_device_index=1,\n", " frames_per_buffer=chunk)\n", "\n", " frames = []\n", "\n", " while not messages.empty():\n", " data = stream.read(chunk)\n", " frames.append(data)\n", "\n", " if len(frames) >= int(FRAME_RATE * RECORD_SECONDS / chunk):\n", " recordings.put(frames.copy())\n", " frames = []\n", "\n", " stream.stop_stream()\n", " stream.close()\n", " p.terminate()\n" ] }, { "cell_type": "code", "execution_count": 33, "id": "931dc754-e034-45e7-981b-a9210c1fe6e9", "metadata": {}, "outputs": [], "source": [ "import subprocess\n", "import json\n", "from vosk import Model, KaldiRecognizer\n", "\n", "model = Model(model_name=\"vosk-model-en-us-0.42-gigaspeech\")\n", "rec = KaldiRecognizer(model, FRAME_RATE)\n", "rec.SetWords(True)\n", "\n", "def speech_recognition(output):\n", " while not messages.empty():\n", " frames = recordings.get()\n", "\n", " rec.AcceptWaveform(b''.join(frames))\n", " result = rec.Result()\n", " text = json.loads(result)[\"text\"]\n", "\n", " cased = subprocess.check_output(\"python recasepunc/recasepunc.py predict recasepunc/checkpoint\", shell=True, text=True, input=text)\n", " output.append_stdout(cased)" ] }, { "cell_type": "code", "execution_count": 1, "id": "a27fb138-d3a9-4e04-83fe-23aca2921d92", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: gradio in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (4.36.1)\n", "Requirement already satisfied: aiofiles<24.0,>=22.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (23.2.1)\n", "Requirement already satisfied: altair<6.0,>=4.2.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (5.3.0)\n", "Requirement already satisfied: fastapi in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.111.0)\n", "Requirement already satisfied: ffmpy in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.3.2)\n", "Requirement already satisfied: gradio-client==1.0.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (1.0.1)\n", "Requirement already satisfied: httpx>=0.24.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.27.0)\n", "Requirement already satisfied: huggingface-hub>=0.19.3 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.23.4)\n", "Requirement already satisfied: importlib-resources<7.0,>=1.3 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (6.4.0)\n", "Requirement already satisfied: jinja2<4.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (3.1.4)\n", "Requirement already satisfied: markupsafe~=2.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (2.1.5)\n", "Requirement already satisfied: matplotlib~=3.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (3.9.0)\n", "Requirement already satisfied: numpy<3.0,>=1.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (1.26.4)\n", "Requirement already satisfied: orjson~=3.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (3.10.5)\n", "Requirement already satisfied: packaging in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (24.1)\n", "Requirement already satisfied: pandas<3.0,>=1.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (2.2.2)\n", "Requirement already satisfied: pillow<11.0,>=8.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (10.3.0)\n", "Requirement already satisfied: pydantic>=2.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (2.7.4)\n", "Requirement already satisfied: pydub in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.25.1)\n", "Requirement already satisfied: python-multipart>=0.0.9 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.0.9)\n", "Requirement already satisfied: pyyaml<7.0,>=5.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (6.0.1)\n", "Requirement already satisfied: ruff>=0.2.2 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.4.10)\n", "Requirement already satisfied: semantic-version~=2.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (2.10.0)\n", "Requirement already satisfied: tomlkit==0.12.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.12.0)\n", "Requirement already satisfied: typer<1.0,>=0.12 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.12.3)\n", "Requirement already satisfied: typing-extensions~=4.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (4.12.2)\n", "Requirement already satisfied: urllib3~=2.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (2.2.1)\n", "Requirement already satisfied: uvicorn>=0.14.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio) (0.30.1)\n", "Requirement already satisfied: fsspec in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio-client==1.0.1->gradio) (2024.6.0)\n", "Requirement already satisfied: websockets<12.0,>=10.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gradio-client==1.0.1->gradio) (11.0.3)\n", "Requirement already satisfied: jsonschema>=3.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from altair<6.0,>=4.2.0->gradio) (4.22.0)\n", "Requirement already satisfied: toolz in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from altair<6.0,>=4.2.0->gradio) (0.12.1)\n", "Requirement already satisfied: anyio in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from httpx>=0.24.1->gradio) (4.4.0)\n", "Requirement already satisfied: certifi in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from httpx>=0.24.1->gradio) (2024.6.2)\n", "Requirement already satisfied: httpcore==1.* in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from httpx>=0.24.1->gradio) (1.0.5)\n", "Requirement already satisfied: idna in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from httpx>=0.24.1->gradio) (3.7)\n", "Requirement already satisfied: sniffio in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from httpx>=0.24.1->gradio) (1.3.1)\n", "Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n", "Requirement already satisfied: filelock in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from huggingface-hub>=0.19.3->gradio) (3.15.1)\n", "Requirement already satisfied: requests in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from huggingface-hub>=0.19.3->gradio) (2.32.3)\n", "Requirement already satisfied: tqdm>=4.42.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from huggingface-hub>=0.19.3->gradio) (4.66.4)\n", "Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from matplotlib~=3.0->gradio) (1.2.1)\n", "Requirement already satisfied: cycler>=0.10 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from matplotlib~=3.0->gradio) (0.12.1)\n", "Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from matplotlib~=3.0->gradio) (4.53.0)\n", "Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from matplotlib~=3.0->gradio) (1.4.5)\n", "Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from matplotlib~=3.0->gradio) (3.1.2)\n", "Requirement already satisfied: python-dateutil>=2.7 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from matplotlib~=3.0->gradio) (2.9.0.post0)\n", "Requirement already satisfied: pytz>=2020.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n", "Requirement already satisfied: tzdata>=2022.7 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n", "Requirement already satisfied: annotated-types>=0.4.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from pydantic>=2.0->gradio) (0.7.0)\n", "Requirement already satisfied: pydantic-core==2.18.4 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from pydantic>=2.0->gradio) (2.18.4)\n", "Requirement already satisfied: click>=8.0.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n", "Requirement already satisfied: shellingham>=1.3.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n", "Requirement already satisfied: rich>=10.11.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n", "Requirement already satisfied: starlette<0.38.0,>=0.37.2 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from fastapi->gradio) (0.37.2)\n", "Requirement already satisfied: fastapi-cli>=0.0.2 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from fastapi->gradio) (0.0.4)\n", "Requirement already satisfied: ujson!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,>=4.0.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from fastapi->gradio) (5.10.0)\n", "Requirement already satisfied: email_validator>=2.0.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from fastapi->gradio) (2.2.0)\n", "Requirement already satisfied: colorama in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from click>=8.0.0->typer<1.0,>=0.12->gradio) (0.4.6)\n", "Requirement already satisfied: dnspython>=2.0.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from email_validator>=2.0.0->fastapi->gradio) (2.6.1)\n", "Requirement already satisfied: attrs>=22.2.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.2.0)\n", "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.12.1)\n", "Requirement already satisfied: referencing>=0.28.4 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.35.1)\n", "Requirement already satisfied: rpds-py>=0.7.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.18.1)\n", "Requirement already satisfied: six>=1.5 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n", "Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.18.0)\n", "Requirement already satisfied: httptools>=0.5.0 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from uvicorn[standard]>=0.12.0->fastapi->gradio) (0.6.1)\n", "Requirement already satisfied: python-dotenv>=0.13 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from uvicorn[standard]>=0.12.0->fastapi->gradio) (1.0.1)\n", "Requirement already satisfied: watchfiles>=0.13 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from uvicorn[standard]>=0.12.0->fastapi->gradio) (0.22.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n", "Requirement already satisfied: mdurl~=0.1 in c:\\users\\samarth srivastava\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install gradio\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "6d7852a7-88e5-4e39-afae-da0bad2f72e5", "metadata": {}, "outputs": [], "source": [ "def my_function(input1, input2):\n", " # Process the inputs and generate the output\n", " output = f\"Processed {input1} and {input2}\"\n", " return output\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "c57fb014-6562-4909-b3d2-52a048c9af18", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7861\n", "Running on public URL: https://4e26f42d95143ec249.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import gradio as gr\n", "\n", "# Define the function you want to expose through Gradio\n", "def my_function(input1, input2):\n", " output = f\"Processed {input1} and {input2}\"\n", " return output\n", "\n", "# Create the Gradio interface\n", "iface = gr.Interface(\n", " fn=my_function,\n", " inputs=[gr.Textbox(label=\"Input 1\"), gr.Textbox(label=\"Input 2\")],\n", " outputs=gr.Textbox(label=\"Output\")\n", ")\n", "\n", "# Launch the interface with a public link\n", "iface.launch(share=True)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "bc4e1d90-6688-4205-a0d2-7933fcdc5874", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }