SoulPerforms commited on
Commit
8a1fb54
·
verified ·
1 Parent(s): b93013d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """app.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1WeNkl1pYnT0qeOTsUFooLFLJ1arRHC00
8
+ """
9
+
10
+ import gradio as gr
11
+ from ultralytics import YOLO
12
+ import cv2
13
+ import os
14
+
15
+ def predict_image(image_input):
16
+ image = cv2.imread(image_input)
17
+ # load model
18
+ model = YOLO("best.pt")
19
+ #run predict
20
+ outputs = model.predict(source=image_input)
21
+ results = output[0].cpu().numpy()
22
+
23
+ for i, det in enumerate(results.boxes.xyxy):
24
+ cv2.rectangle(image, (int(det[0]), int(det[1])), (int(det[2]), int(det[3])), color=(0, 0, 255), thickness=2, lineType=cv2.Line_AA)
25
+
26
+ return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
27
+
28
+ inputs_image = [gr.components.Image(type="filepath", label="Input Image")]
29
+
30
+ outputs_image = [gr.components.Image(type="numpy", label="Output Image")]
31
+
32
+ interface_image = gr.Interface(fn = predict_image, inputs=inputs_image, outputs=outputs_image,title="Fire & Smoke Detector", cache_examples=False)
33
+
34
+ interface_image.launch(Debug=True)