feliperafael commited on
Commit
ea7abd5
·
1 Parent(s): fbebe0c
Files changed (4) hide show
  1. README.md +45 -12
  2. app.py +54 -0
  3. marca-cor-fundo-escuro.svg +49 -0
  4. requirements.txt +5 -0
README.md CHANGED
@@ -1,12 +1,45 @@
1
- ---
2
- title: Inference
3
- emoji: 🔥
4
- colorFrom: blue
5
- colorTo: indigo
6
- sdk: streamlit
7
- sdk_version: 1.41.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # YOLOv8 Video/Webcam Inference Streamlit App
2
+
3
+ This is a Streamlit application that uses YOLOv8 models with Ultralytics for real-time inference on videos or webcam feed.
4
+
5
+ ## Requirements
6
+
7
+ - Python 3.7+
8
+ - Streamlit
9
+ - Ultralytics
10
+ - OpenCV
11
+
12
+ ## Installation
13
+
14
+ 1. Clone the repository:
15
+
16
+ ```
17
+ git clone https://github.com/your-username/yolov8-streamlit-app.git
18
+ cd yolov8-streamlit-app
19
+ ```
20
+
21
+ 2. Install the dependencies:
22
+
23
+ ```
24
+ pip install -r requirements.txt
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ 1. Download the YOLOv8 model file (`yolov8n.pt`) and place it in the project directory.
30
+
31
+ 2. Run the Streamlit app:
32
+
33
+ ```
34
+ streamlit run app.py
35
+ ```
36
+
37
+ 3. Open the app in your web browser using the provided URL.
38
+
39
+ 4. Upload a video file or select the "Use webcam" option to start the inference.
40
+
41
+ 5. The app will display the inference results on the video frames or webcam feed in real-time.
42
+
43
+ ## License
44
+
45
+ This project is licensed under the MIT License.
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from ultralytics import YOLO
3
+ import cv2
4
+ from PIL import Image
5
+ from io import BytesIO
6
+ import cairosvg
7
+
8
+ # Read the SVG logo file
9
+ with open("marca-cor-fundo-escuro.svg", "r") as f:
10
+ logo_svg = f.read()
11
+
12
+ # Convert SVG to PNG using cairosvg
13
+ logo_png_bytes = cairosvg.svg2png(bytestring=logo_svg.encode())
14
+ logo_png = Image.open(BytesIO(logo_png_bytes))
15
+
16
+ # Display the logo
17
+ st.image(logo_png, width=200)
18
+
19
+ # Load the YOLOv8 model
20
+ model = YOLO('yolov8n.pt')
21
+
22
+ # Set up the Streamlit app
23
+ #st.title('YOLOv8 Video/Webcam Inference')
24
+
25
+ # Add file uploader or webcam option
26
+ video_file = st.file_uploader("Upload a video", type=["mp4", "avi"])
27
+ use_webcam = st.checkbox("Use webcam")
28
+
29
+ # Placeholder for inference results
30
+ inference_placeholder = st.empty()
31
+
32
+ # Video/webcam inference loop
33
+ if video_file is not None or use_webcam:
34
+ if video_file is not None:
35
+ video = cv2.VideoCapture(video_file.name)
36
+ else:
37
+ video = cv2.VideoCapture(0) # Use webcam
38
+
39
+ while True:
40
+ ret, frame = video.read()
41
+ if not ret:
42
+ break
43
+
44
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
45
+
46
+ # Run YOLOv8 inference on the frame
47
+ results = model(frame)
48
+
49
+ # Display the inference results
50
+ inference_placeholder.image(results[0].plot(), use_container_width=True)
51
+
52
+ video.release()
53
+ else:
54
+ st.warning("Please upload a video file or select the webcam option.")
marca-cor-fundo-escuro.svg ADDED
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ ultralytics
3
+ opencv-python
4
+ pillow
5
+ cairosvg