Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +50 -0
- requirements.txt +6 -0
- welding.pt +3 -0
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_webrtc import webrtc_streamer, VideoTransformerBase
|
| 3 |
+
import av
|
| 4 |
+
import cv2
|
| 5 |
+
import numpy as np
|
| 6 |
+
from PIL import Image
|
| 7 |
+
from ultralytics import YOLO
|
| 8 |
+
|
| 9 |
+
# Load the YOLO model
|
| 10 |
+
model = YOLO("welding.pt")
|
| 11 |
+
|
| 12 |
+
st.set_page_config(page_title="Welding Detection App", layout="centered")
|
| 13 |
+
st.title("๐ผ๏ธ Welding Detection App with YOLOv8")
|
| 14 |
+
st.markdown("Upload an image or use live webcam feed for detection.")
|
| 15 |
+
|
| 16 |
+
# -------- Image Upload Detection --------
|
| 17 |
+
with st.expander("๐ธ Upload Image for Detection"):
|
| 18 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png", "bmp", "tif", "tiff"])
|
| 19 |
+
if uploaded_file is not None:
|
| 20 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 21 |
+
image_np = np.array(image)
|
| 22 |
+
image_cv = cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR)
|
| 23 |
+
|
| 24 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 25 |
+
|
| 26 |
+
if st.button("๐ Run Detection"):
|
| 27 |
+
with st.spinner("Detecting..."):
|
| 28 |
+
results = model(image_cv, verbose=False)
|
| 29 |
+
detected = results[0].plot()
|
| 30 |
+
detected_rgb = cv2.cvtColor(detected, cv2.COLOR_BGR2RGB)
|
| 31 |
+
st.image(detected_rgb, caption="Detected Image", use_column_width=True)
|
| 32 |
+
st.success("Detection Complete โ
")
|
| 33 |
+
|
| 34 |
+
# -------- Live Camera Detection --------
|
| 35 |
+
st.markdown("---")
|
| 36 |
+
st.subheader("๐ฅ Live Webcam Detection")
|
| 37 |
+
|
| 38 |
+
class YOLOVideoTransformer(VideoTransformerBase):
|
| 39 |
+
def transform(self, frame: av.VideoFrame) -> np.ndarray:
|
| 40 |
+
image = frame.to_ndarray(format="bgr24")
|
| 41 |
+
results = model(image, verbose=False)
|
| 42 |
+
annotated_frame = results[0].plot()
|
| 43 |
+
return annotated_frame
|
| 44 |
+
|
| 45 |
+
webrtc_streamer(
|
| 46 |
+
key="live",
|
| 47 |
+
video_processor_factory=YOLOVideoTransformer,
|
| 48 |
+
media_stream_constraints={"video": True, "audio": False},
|
| 49 |
+
async_processing=True,
|
| 50 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
gradio
|
| 3 |
+
opencv-python
|
| 4 |
+
torch
|
| 5 |
+
ultralytics
|
| 6 |
+
pillow
|
welding.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:761f6bcf0c19832068f485013d3ff80eb74615f99eab86f588ae8f2c22175989
|
| 3 |
+
size 5478419
|