harshj0506 commited on
Commit
8ab6462
·
verified ·
1 Parent(s): 3889af6

Upload 7 files

Browse files
Files changed (8) hide show
  1. .gitattributes +2 -0
  2. README.md +5 -5
  3. app.py +101 -0
  4. converted_image.jpg +0 -0
  5. demovideo (1).mp4 +3 -0
  6. requirements (1).txt +3 -0
  7. result.mp4 +0 -0
  8. vid1 (1).mp4 +3 -0
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ demovideo[[:space:]](1).mp4 filter=lfs diff=lfs merge=lfs -text
37
+ vid1[[:space:]](1).mp4 filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Demo2
3
- emoji: 📈
4
- colorFrom: pink
5
- colorTo: pink
6
  sdk: streamlit
7
- sdk_version: 1.34.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
+ title: Demo
3
+ emoji:
4
+ colorFrom: gray
5
+ colorTo: indigo
6
  sdk: streamlit
7
+ sdk_version: 1.33.0
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from ultralytics import YOLO
3
+ import os
4
+ from os import listdir, remove
5
+ from PIL import Image
6
+ import cv2
7
+
8
+
9
+ import requests
10
+
11
+ def download_file(url, destination_folder):
12
+ """
13
+ Download a file from a URL and save it to a local destination.
14
+
15
+ Args:
16
+ url (str): The URL of the file to download.
17
+ destination_folder (str): The local folder where the file should be saved.
18
+ """
19
+ # Create the destination folder if it doesn't exist
20
+ if not os.path.exists(destination_folder):
21
+ os.makedirs(destination_folder)
22
+
23
+ # Extract filename from URL
24
+ filename = url.split('/')[-1]
25
+ destination_path = os.path.join(destination_folder, filename)
26
+
27
+ # Download the file
28
+ with open(destination_path, 'wb') as f:
29
+ response = requests.get(url)
30
+ f.write(response.content)
31
+
32
+ return destination_path
33
+
34
+ url = 'https://yolo-v8-models.s3.ap-south-1.amazonaws.com/best.pt'
35
+ destination_folder = 'models'
36
+
37
+ downloaded_file = download_file(url, destination_folder)
38
+
39
+ # Load the model
40
+ model = YOLO('models/best.pt')
41
+
42
+ # Streamlit UI
43
+ st.title("Object Detection with Ultralytics")
44
+
45
+ # Upload image or video
46
+ uploaded_file = st.file_uploader("Choose an image or video", type=["jpg", "jpeg", "png","mp4"])
47
+
48
+ # Demo section
49
+ st.header("Demo")
50
+ col1, col2 = st.columns(2)
51
+
52
+ # Display image in first column
53
+ with col1:
54
+ st.image("demoimg.jpeg", caption="Annotated Image", use_column_width=True)
55
+
56
+ # Display video in second column with adjusted width
57
+ with col2:
58
+ st.write(f'<div style="width: {300};height :500">', unsafe_allow_html=True)
59
+ st.video("demovideo.mp4")
60
+ st.write('</div>', unsafe_allow_html=True)
61
+
62
+ if uploaded_file is not None:
63
+ # Check if the uploaded file is a video
64
+ if uploaded_file.type.startswith("video/"):
65
+ # Progress bar to show the progress of object detection
66
+ progress_bar = st.progress(0)
67
+
68
+ st.header(uploaded_file.name)
69
+
70
+ # Perform object detection
71
+ with st.spinner('Performing object detection...'):
72
+ for percent_complete in range(100):
73
+ result = model.predict(source=uploaded_file, conf=0.2, save=True ,stream=True)
74
+ for i in result : i.save("video.mp4")
75
+ progress_bar.progress(percent_complete + 1)
76
+
77
+ st.success(f"Video saved successfully ")
78
+ # Perform object detection
79
+
80
+
81
+ else:
82
+
83
+ # Read the uploaded image
84
+ image = Image.open(uploaded_file)
85
+
86
+ img_name = "converted_image.jpg"
87
+ image.save(img_name)
88
+
89
+ # Perform object detection
90
+ result = model.predict(source=img_name, conf=0.2, save=True)
91
+
92
+ # Save the output image
93
+ img_save_path = "output/"
94
+ os.makedirs(img_save_path, exist_ok=True)
95
+ for r in result:
96
+ r.save(filename=os.path.join(img_save_path, uploaded_file.name))
97
+
98
+ st.success("Detected Object")
99
+ # Display the output image
100
+ st.image(os.path.join(img_save_path, uploaded_file.name), caption="Detected Objects", use_column_width=True)
101
+
converted_image.jpg ADDED
demovideo (1).mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:175719051e82eaaa3e9858d37311a4708a846e7689594d83e89d576d3cf22469
3
+ size 4379698
requirements (1).txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ ultralytics
3
+ Pillow
result.mp4 ADDED
Binary file (258 Bytes). View file
 
vid1 (1).mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d31a8d40a9ee2d02ab0fe4632c2581e8bcceb2750563db0da0876ed8f875f5fc
3
+ size 3622242