Spaces:
Sleeping
Sleeping
File size: 6,233 Bytes
6e11613 6619af4 6e11613 6619af4 6e11613 a89aba1 6619af4 a89aba1 6e11613 a89aba1 6e11613 a89aba1 6e11613 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
{
"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": [
"<div><iframe src=\"https://fa61d92c4dbab3b5e3.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"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
}
|