Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +27 -21
streamlit_app.py
CHANGED
@@ -107,29 +107,35 @@ st.write("Identify butterflies using your camera or by uploading an image!")
|
|
107 |
tab1, tab2 = st.tabs(["📷 Live Camera", "📁 Upload Image"])
|
108 |
|
109 |
with tab1:
|
110 |
-
st.header("
|
111 |
-
st.write("
|
112 |
|
113 |
-
#
|
114 |
-
|
115 |
-
"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
|
116 |
-
})
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
with tab2:
|
135 |
st.header("Upload Image")
|
|
|
107 |
tab1, tab2 = st.tabs(["📷 Live Camera", "📁 Upload Image"])
|
108 |
|
109 |
with tab1:
|
110 |
+
st.header("Camera Capture")
|
111 |
+
st.write("Take a photo of a butterfly for identification!")
|
112 |
|
113 |
+
# Use Streamlit's built-in camera input
|
114 |
+
camera_photo = st.camera_input("Take a picture of a butterfly")
|
|
|
|
|
115 |
|
116 |
+
if camera_photo is not None:
|
117 |
+
try:
|
118 |
+
# Convert to PIL Image
|
119 |
+
image = Image.open(camera_photo).convert("RGB")
|
120 |
+
|
121 |
+
col1, col2 = st.columns(2)
|
122 |
+
|
123 |
+
with col1:
|
124 |
+
st.image(image, caption="Captured Image", use_column_width=True)
|
125 |
+
|
126 |
+
with col2:
|
127 |
+
predicted_class, confidence = predict_butterfly(image)
|
128 |
+
|
129 |
+
if predicted_class:
|
130 |
+
st.success(f"**Prediction: {predicted_class}**")
|
131 |
+
st.info(f"Confidence: {confidence:.2%}")
|
132 |
+
|
133 |
+
if predicted_class in butterfly_info:
|
134 |
+
st.write("**Species Information:**")
|
135 |
+
st.write(butterfly_info[predicted_class]["description"])
|
136 |
+
|
137 |
+
except Exception as e:
|
138 |
+
st.error(f"Error processing image: {str(e)}")
|
139 |
|
140 |
with tab2:
|
141 |
st.header("Upload Image")
|