leynessa commited on
Commit
38a7793
·
verified ·
1 Parent(s): bfc9fea

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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("Live Camera Identification")
111
- st.write("Point your camera at a butterfly and get real-time identification!")
112
 
113
- # WebRTC configuration
114
- RTC_CONFIGURATION = RTCConfiguration({
115
- "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
116
- })
117
 
118
- # Camera streamer
119
- webrtc_ctx = webrtc_streamer(
120
- key="butterfly-camera",
121
- mode=WebRtcMode.SENDRECV,
122
- rtc_configuration=RTC_CONFIGURATION,
123
- video_processor_factory=VideoProcessor,
124
- media_stream_constraints={"video": True, "audio": False},
125
- async_processing=True,
126
- )
127
-
128
- st.info("💡 Tips for best results:")
129
- st.write("- Hold the camera steady")
130
- st.write("- Ensure good lighting")
131
- st.write("- Get close to the butterfly")
132
- st.write("- Wait for the green prediction text to appear")
 
 
 
 
 
 
 
 
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")