Update src/streamlit_app.py
Browse files- src/streamlit_app.py +6 -16
src/streamlit_app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from ultralytics import YOLO
|
| 3 |
-
from keras.utils import get_file
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
|
|
@@ -12,14 +11,13 @@ st.set_page_config(
|
|
| 12 |
initial_sidebar_state="expanded",
|
| 13 |
)
|
| 14 |
|
| 15 |
-
# ---
|
| 16 |
st.markdown("""
|
| 17 |
<style>
|
| 18 |
/* --- Base Styles (Shared) --- */
|
| 19 |
.st-expander {
|
| 20 |
border-radius: 10px;
|
| 21 |
}
|
| 22 |
-
|
| 23 |
/* --- LIGHT THEME --- */
|
| 24 |
[data-theme="light"] .stApp {
|
| 25 |
background-color: #f0f2f6; /* Light gray background */
|
|
@@ -34,7 +32,6 @@ st.markdown("""
|
|
| 34 |
border: 1px solid #ddd;
|
| 35 |
background-color: #ffffff;
|
| 36 |
}
|
| 37 |
-
|
| 38 |
/* --- DARK THEME --- */
|
| 39 |
[data-theme="dark"] .stApp {
|
| 40 |
background-color: #0E1117; /* Default Streamlit dark background */
|
|
@@ -57,7 +54,6 @@ st.markdown("""
|
|
| 57 |
""", unsafe_allow_html=True)
|
| 58 |
|
| 59 |
# --- Model Loading ---
|
| 60 |
-
# Use st.cache_resource to load the model only once
|
| 61 |
@st.cache_resource
|
| 62 |
def load_model(model_path):
|
| 63 |
"""
|
|
@@ -71,13 +67,8 @@ def load_model(model_path):
|
|
| 71 |
st.error(f"Error loading model: {e}")
|
| 72 |
return None
|
| 73 |
|
| 74 |
-
#
|
| 75 |
-
# force_download=False,
|
| 76 |
-
# origin="https://huggingface.co/CineAI/RSSI/resolve/main/rssi_last.pt",
|
| 77 |
-
# file_hash="c689b8a006e574bf5e4f2ff252230cb59ac3de42ca24875000144c2f552bd837"
|
| 78 |
-
# )
|
| 79 |
MODEL_PATH = './src/rssi_last.pt'
|
| 80 |
-
print(f"MODEL_PATH: {MODEL_PATH}")
|
| 81 |
model = load_model(MODEL_PATH)
|
| 82 |
|
| 83 |
# --- Sidebar ---
|
|
@@ -89,7 +80,6 @@ st.sidebar.markdown("---")
|
|
| 89 |
uploaded_file = st.sidebar.file_uploader(
|
| 90 |
"Upload an image...", type=["jpg", "jpeg", "png"]
|
| 91 |
)
|
| 92 |
-
|
| 93 |
st.sidebar.markdown("---")
|
| 94 |
st.sidebar.markdown(
|
| 95 |
"**About this App**\n\n"
|
|
@@ -99,10 +89,8 @@ st.sidebar.markdown(
|
|
| 99 |
|
| 100 |
# --- Main Page ---
|
| 101 |
st.title("🖼️ Custom Object Detection with YOLO")
|
| 102 |
-
st.write("Upload an image via the sidebar to see the model's predictions.")
|
| 103 |
|
| 104 |
if uploaded_file is not None:
|
| 105 |
-
print(f"uploaded_file: {uploaded_file}")
|
| 106 |
# Read the uploaded image file
|
| 107 |
image_data = uploaded_file.getvalue()
|
| 108 |
original_image = Image.open(io.BytesIO(image_data))
|
|
@@ -112,7 +100,8 @@ if uploaded_file is not None:
|
|
| 112 |
|
| 113 |
with col1:
|
| 114 |
st.subheader("Original Image")
|
| 115 |
-
|
|
|
|
| 116 |
|
| 117 |
if model:
|
| 118 |
# Perform inference
|
|
@@ -129,7 +118,8 @@ if uploaded_file is not None:
|
|
| 129 |
|
| 130 |
with col2:
|
| 131 |
st.subheader("Detected Objects")
|
| 132 |
-
|
|
|
|
| 133 |
|
| 134 |
# Display detection details
|
| 135 |
st.subheader("Detection Details")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from ultralytics import YOLO
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
|
|
|
|
| 11 |
initial_sidebar_state="expanded",
|
| 12 |
)
|
| 13 |
|
| 14 |
+
# --- Theme-Aware Custom CSS ---
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
/* --- Base Styles (Shared) --- */
|
| 18 |
.st-expander {
|
| 19 |
border-radius: 10px;
|
| 20 |
}
|
|
|
|
| 21 |
/* --- LIGHT THEME --- */
|
| 22 |
[data-theme="light"] .stApp {
|
| 23 |
background-color: #f0f2f6; /* Light gray background */
|
|
|
|
| 32 |
border: 1px solid #ddd;
|
| 33 |
background-color: #ffffff;
|
| 34 |
}
|
|
|
|
| 35 |
/* --- DARK THEME --- */
|
| 36 |
[data-theme="dark"] .stApp {
|
| 37 |
background-color: #0E1117; /* Default Streamlit dark background */
|
|
|
|
| 54 |
""", unsafe_allow_html=True)
|
| 55 |
|
| 56 |
# --- Model Loading ---
|
|
|
|
| 57 |
@st.cache_resource
|
| 58 |
def load_model(model_path):
|
| 59 |
"""
|
|
|
|
| 67 |
st.error(f"Error loading model: {e}")
|
| 68 |
return None
|
| 69 |
|
| 70 |
+
# Path to the model file inside the 'src' directory
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
MODEL_PATH = './src/rssi_last.pt'
|
|
|
|
| 72 |
model = load_model(MODEL_PATH)
|
| 73 |
|
| 74 |
# --- Sidebar ---
|
|
|
|
| 80 |
uploaded_file = st.sidebar.file_uploader(
|
| 81 |
"Upload an image...", type=["jpg", "jpeg", "png"]
|
| 82 |
)
|
|
|
|
| 83 |
st.sidebar.markdown("---")
|
| 84 |
st.sidebar.markdown(
|
| 85 |
"**About this App**\n\n"
|
|
|
|
| 89 |
|
| 90 |
# --- Main Page ---
|
| 91 |
st.title("🖼️ Custom Object Detection with YOLO")
|
|
|
|
| 92 |
|
| 93 |
if uploaded_file is not None:
|
|
|
|
| 94 |
# Read the uploaded image file
|
| 95 |
image_data = uploaded_file.getvalue()
|
| 96 |
original_image = Image.open(io.BytesIO(image_data))
|
|
|
|
| 100 |
|
| 101 |
with col1:
|
| 102 |
st.subheader("Original Image")
|
| 103 |
+
# CHANGED: use_container_width is the new, recommended parameter
|
| 104 |
+
st.image(original_image, caption="Your uploaded image.", use_container_width=True)
|
| 105 |
|
| 106 |
if model:
|
| 107 |
# Perform inference
|
|
|
|
| 118 |
|
| 119 |
with col2:
|
| 120 |
st.subheader("Detected Objects")
|
| 121 |
+
# CHANGED: use_container_width is the new, recommended parameter
|
| 122 |
+
st.image(annotated_image_rgb, caption="Image with detected objects.", use_container_width=True)
|
| 123 |
|
| 124 |
# Display detection details
|
| 125 |
st.subheader("Detection Details")
|