{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/shiv-nlp-mldl-cv/anaconda3/envs/S15-Yolo1/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "Running on public URL: https://fa61d92c4dbab3b5e3.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": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import gradio as gr\n", "from PIL import Image\n", "import numpy as np\n", "import os\n", "import uuid\n", "\n", "def inference(input_img):\n", " temp = uuid.uuid4()\n", " shell = f\"python yolov9/detect.py --source {input_img} --img 640 --device cpu --weights yolov9/runs/train/exp/weights/best.pt --name {temp}\"\n", " os.system(shell)\n", " return f\"yolov9/runs/detect/{temp}/{input_img.split('/')[-1]}\"\n", " #return \"yolov9/runs/detect/f807164a-496b-413c-bb47-f5daf8803dcd/cut_a_1.mp4\"\n", "\n", "def inference_video(input_img):\n", " org_img = input_img\n", " return input_img\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\n", " \"\"\"\n", " # Vehicle detection using Yolo-v9\n", " \"\"\"\n", " )\n", "\n", " with gr.Tab(\"Video\"):\n", " gr.Markdown(\n", " \"\"\"\n", " Upload image file and detect vehicles present in the image\n", " \"\"\"\n", " )\n", " with gr.Row():\n", " img_input = [gr.PlayableVideo(label=\"Input Image\", autoplay=True, width=300, height=300)]\n", " pred_outputs = [gr.PlayableVideo(label=\"Output Image\",width=640, autoplay=True, height=640)]\n", " \n", " gr.Markdown(\"## Examples\")\n", "\n", " with gr.Row(): \n", " gr.Examples([ \n", " 'cut_a_2.mp4',\n", " 'cut_b_1.mp4','tresa.mp4'], \n", " inputs=img_input, fn=inference)\n", " \n", " image_button = gr.Button(\"Predict\")\n", " image_button.click(inference, inputs=img_input, outputs=pred_outputs)\n", "\n", " with gr.Tab(\"Image\"):\n", " \n", " \n", " gr.Markdown(\n", " \"\"\"\n", " Upload image file and detect vehicles present in the image\n", " \"\"\"\n", " )\n", " with gr.Row():\n", " img_input = [gr.Image(type=\"filepath\",label=\"Input Image\",width=300, height=300)]\n", " pred_outputs = [gr.Image(label=\"Output Image\",width=640, height=640)]\n", "\n", " gr.Markdown(\"## Examples\")\n", "\n", " with gr.Row(): \n", " gr.Examples([ \n", " 'rohan.jpg',\n", " 'lamborghini-aventador-2932196_1280.jpg', \n", " '0KL1ICR33YYZ.jpg',\n", " '0RVD53V60NOM.jpg',\n", " '0RW4I2NTAH8K.jpg',\n", " '1CSLEJ2UJD3G.jpg',\n", " '1E4CD5K13UXO.jpg',\n", " '2.jpg',\n", " 'truck.jpg',\n", " '3BXRTQZ70A7M.jpg',\n", " '3GVLVIQ2J4P2.jpg',\n", " '3RIYE11PE0VK.jpg',\n", " '4AS6VDRS3Y07.jpg',\n", " '4DM206U83T3B.jpg',\n", " '05U2U2R2K6DN.jpg',\n", " '6LBV93O0MWUY.jpg',\n", " '6MFW23QQFW3E.jpg',\n", " '6V4OYHB47QOX.jpg',\n", " '6VOUS49LKRLI.jpg',\n", " '6VOUS49LKRLI.jpg',\n", " '7L1KFQDNLCBY.jpg',\n", " '23BNPRMYV2RT.jpg',\n", " '24IHCQ74TBML.jpg',\n", " '38EE8ZBTSGD1.jpg',\n", " '05U2U2R2K6DN.jpg',\n", " '0KL1ICR33YYZ.jpg'\n", " ], \n", " inputs=img_input, fn=inference)\n", " image_button = gr.Button(\"Predict\")\n", " image_button.click(inference, inputs=img_input, outputs=pred_outputs)\n", "\n", " \n", "\n", "\n", "\n", "demo.launch(share=True)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "S6-VSCode", "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.10.14" } }, "nbformat": 4, "nbformat_minor": 2 }