Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from ultralytics import YOLO
|
| 3 |
-
import cv2
|
| 4 |
-
import numpy as np
|
| 5 |
-
from PIL import Image
|
| 6 |
|
| 7 |
-
model = YOLO("best.pt")
|
| 8 |
-
model.predict(source=0,imgsize=640,conf=0.6,show=True)
|
| 9 |
|
| 10 |
|
| 11 |
# # Load the YOLO model (replace with your model path)
|
|
@@ -151,5 +151,33 @@ model.predict(source=0,imgsize=640,conf=0.6,show=True)
|
|
| 151 |
# # Release the video capture
|
| 152 |
# video_capture.release()
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
# from ultralytics import YOLO
|
| 3 |
+
# import cv2
|
| 4 |
+
# import numpy as np
|
| 5 |
+
# from PIL import Image
|
| 6 |
|
| 7 |
+
# model = YOLO("best.pt")
|
| 8 |
+
# model.predict(source=0,imgsize=640,conf=0.6,show=True)
|
| 9 |
|
| 10 |
|
| 11 |
# # Load the YOLO model (replace with your model path)
|
|
|
|
| 151 |
# # Release the video capture
|
| 152 |
# video_capture.release()
|
| 153 |
|
| 154 |
+
|
| 155 |
+
import torch
|
| 156 |
+
import gradio as gr
|
| 157 |
+
from PIL import Image
|
| 158 |
+
|
| 159 |
+
# Load the YOLOv11 model
|
| 160 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', source='local') # replace 'yolov5' with 'yolo11' if needed
|
| 161 |
+
|
| 162 |
+
# Define the prediction function
|
| 163 |
+
def detect_fire(image):
|
| 164 |
+
# Run the YOLO model on the uploaded image
|
| 165 |
+
results = model(image)
|
| 166 |
+
# Check if fire is detected based on the model's output classes
|
| 167 |
+
detected = any('fire' in results.names[label] for label in results.xyxy[0][:, -1].tolist())
|
| 168 |
+
return "Fire Detected" if detected else "No Fire Detected"
|
| 169 |
+
|
| 170 |
+
# Create and launch the Gradio interface
|
| 171 |
+
interface = gr.Interface(
|
| 172 |
+
fn=detect_fire,
|
| 173 |
+
inputs=gr.Image(type='pil', label="Upload Image"),
|
| 174 |
+
outputs="text",
|
| 175 |
+
title="Fire Detection with YOLOv11",
|
| 176 |
+
description="Upload an image to classify whether fire is detected or not."
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
interface.launch()
|
| 180 |
+
|
| 181 |
+
|
| 182 |
|
| 183 |
|