avinashsingh1 commited on
Commit
8f3e1c4
·
verified ·
1 Parent(s): 891e15a

Upload 5 files

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. Custom_model.keras +3 -0
  3. Dockerfile +12 -20
  4. best.pt +3 -0
  5. requirements.txt +6 -3
  6. streamlit_app.py +89 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ 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
+ Custom_model.keras filter=lfs diff=lfs merge=lfs -text
Custom_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f5781aa28b54fa7fd44270ee80251b8865eaf72eb39536222f0b95963190a3e6
3
+ size 11650436
Dockerfile CHANGED
@@ -1,20 +1,12 @@
1
- FROM python:3.13.5-slim
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
-
14
- RUN pip3 install -r requirements.txt
15
-
16
- EXPOSE 8501
17
-
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
-
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /app
4
+
5
+ COPY . /app
6
+
7
+ RUN pip install --upgrade pip
8
+ RUN pip install -r requirements.txt
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.address=0.0.0.0"]
 
 
 
 
 
 
 
 
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:395c0ab605717d9418b5c50662a7010067bd39f520a0a812ef9aed9d062a9670
3
+ size 6216234
requirements.txt CHANGED
@@ -1,3 +1,6 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
1
+ streamlit
2
+ ultralytics
3
+ tensorflow==2.13.0
4
+ opencv-python-headless
5
+ pillow
6
+ numpy
streamlit_app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ import numpy as np
5
+ import tempfile
6
+ import tensorflow as tf
7
+ from io import BytesIO
8
+
9
+ # Page Config
10
+ st.set_page_config(page_title="Drone vs Bird", layout="wide")
11
+
12
+ st.markdown(
13
+ "<h1 style='text-align:center;'>Drone vs Bird Detection</h1>",
14
+ unsafe_allow_html=True
15
+ )
16
+
17
+ # Load models (cached)
18
+ @st.cache_resource
19
+ def load_models():
20
+ model = tf.keras.models.load_model("Custom_model.keras")
21
+ yolomodel = YOLO("best.pt") # FIXED PATH
22
+ return model, yolomodel
23
+
24
+ model, yolomodel = load_models()
25
+
26
+ class_names = ["Bird", "Drone"]
27
+
28
+ # Sidebar
29
+ uploaded_file = st.sidebar.file_uploader("Upload Image", type=["jpg","png","jpeg"])
30
+ run_mobilenet = st.sidebar.button("Run Classification")
31
+ run_yolo = st.sidebar.button("Run Detection")
32
+
33
+ # Main UI
34
+ if uploaded_file:
35
+
36
+ col1, col2 = st.columns([1.2,1])
37
+
38
+ with col1:
39
+ image = Image.open(uploaded_file).convert("RGB")
40
+ st.image(image, caption="Uploaded Image", use_container_width=True)
41
+
42
+ temp = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg")
43
+ image.save(temp.name)
44
+
45
+ with col2:
46
+
47
+ # ✅ MobileNet
48
+ if run_mobilenet:
49
+ img = image.resize((224,224))
50
+ img_array = np.array(img)/255.0
51
+ img_array = np.expand_dims(img_array, axis=0)
52
+
53
+ preds = model.predict(img_array)
54
+ label = class_names[int(preds[0][0] >= 0.5)]
55
+
56
+ st.success(f"Prediction: {label}")
57
+
58
+ # ✅ YOLO
59
+ if run_yolo:
60
+ results = yolomodel.predict(temp.name, conf=0.25)
61
+
62
+ annotated = results[0].plot()
63
+ annotated = annotated[:,:,::-1]
64
+
65
+ st.image(annotated, caption="Detection", use_container_width=True)
66
+
67
+ detections = results[0].boxes
68
+
69
+ if len(detections) == 0:
70
+ st.warning("No objects detected")
71
+ else:
72
+ for box in detections:
73
+ cls = int(box.cls[0])
74
+ conf = float(box.conf[0])*100
75
+ st.write(f"{yolomodel.names[cls]} — {conf:.2f}%")
76
+
77
+ # Download
78
+ pil_img = Image.fromarray(annotated)
79
+ buf = BytesIO()
80
+ pil_img.save(buf, format="PNG")
81
+
82
+ st.download_button(
83
+ "Download Result",
84
+ buf.getvalue(),
85
+ file_name="result.png"
86
+ )
87
+
88
+ else:
89
+ st.info("Upload an image to start")