SoulPerforms commited on
Commit
6fad636
·
1 Parent(s): 0a231ab

Add application file

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "81598ea8-8e97-4ad7-a45f-bd928d0ef416",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import gradio as gr\n",
11
+ "from ultralytics import YOLO\n",
12
+ "import cv2\n",
13
+ "import os\n",
14
+ "\n",
15
+ "def predict_image(image_input):\n",
16
+ " image = cv2.imread(image_input)\n",
17
+ " # load model\n",
18
+ " model = YOLO(\"best.pt\")\n",
19
+ " #run predict\n",
20
+ " outputs = model.predict(source=image_input)\n",
21
+ " results = output[0].cpu().numpy()\n",
22
+ " for i, det in enumerate(results.boxes.xyxy):\n",
23
+ " cv2.rectangle(image, (int(det[0]), int(det[1]), int(det[2]), int(det[3]),\n",
24
+ " color=(0, 0, 255), thickness=2, lineType=cv2.Line_AA)\n",
25
+ " return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n",
26
+ "\n",
27
+ "inputs_image = [gr.components.Image(type=\"filepath\", label=\"Input Image\")]\n",
28
+ "outputs_image = [gr.components.Image(type=\"numpy\", label=\"Output Image\")]\n",
29
+ "\n",
30
+ "interface_image = gr.Interface(fn = predict_image, inputs=inputs_image, outputs=outputs_image, \n",
31
+ " title=\"Fire & Smoke Detector\", cache_examples=False)\n",
32
+ "\n",
33
+ "interface_image.launch(Debug=True)\n"
34
+ ]
35
+ }
36
+ ],
37
+ "metadata": {
38
+ "kernelspec": {
39
+ "display_name": "Python 3 (ipykernel)",
40
+ "language": "python",
41
+ "name": "python3"
42
+ },
43
+ "language_info": {
44
+ "codemirror_mode": {
45
+ "name": "ipython",
46
+ "version": 3
47
+ },
48
+ "file_extension": ".py",
49
+ "mimetype": "text/x-python",
50
+ "name": "python",
51
+ "nbconvert_exporter": "python",
52
+ "pygments_lexer": "ipython3",
53
+ "version": "3.9.18"
54
+ }
55
+ },
56
+ "nbformat": 4,
57
+ "nbformat_minor": 5
58
+ }