Spaces:
Sleeping
Sleeping
Commit
·
d1cbfa2
1
Parent(s):
d033fd0
feat: Añadidos mensajes sobre limitaciones de video streaming en Hugging Face Spaces
Browse files- streamlit_app.py +39 -15
streamlit_app.py
CHANGED
|
@@ -451,6 +451,38 @@ def main():
|
|
| 451 |
st.session_state.feature_camera_running = False
|
| 452 |
st.session_state.feature_camera_stopped = True
|
| 453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
if app_mode == "About":
|
| 455 |
st.markdown("""
|
| 456 |
## About This App
|
|
@@ -2145,21 +2177,13 @@ def main():
|
|
| 2145 |
if st.session_state.recognition_camera_running:
|
| 2146 |
try:
|
| 2147 |
st.info("Camera activated. Processing video in real-time...")
|
| 2148 |
-
cap =
|
| 2149 |
-
|
| 2150 |
-
|
| 2151 |
-
|
| 2152 |
-
|
| 2153 |
-
|
| 2154 |
-
|
| 2155 |
-
start_time = time.time()
|
| 2156 |
-
last_frame_time = start_time
|
| 2157 |
-
fps_history = []
|
| 2158 |
-
|
| 2159 |
-
while st.session_state.recognition_camera_running:
|
| 2160 |
-
# Process frames here
|
| 2161 |
-
pass
|
| 2162 |
-
|
| 2163 |
except Exception as e:
|
| 2164 |
st.error(str(e))
|
| 2165 |
st.session_state.recognition_camera_running = False
|
|
|
|
| 451 |
st.session_state.feature_camera_running = False
|
| 452 |
st.session_state.feature_camera_stopped = True
|
| 453 |
|
| 454 |
+
def init_camera():
|
| 455 |
+
"""Initialize camera and show appropriate messages."""
|
| 456 |
+
try:
|
| 457 |
+
# Check if we're running on Hugging Face Spaces
|
| 458 |
+
if os.environ.get('SPACE_ID'):
|
| 459 |
+
st.warning("""
|
| 460 |
+
⚠️ Video streaming is limited in Hugging Face Spaces:
|
| 461 |
+
|
| 462 |
+
- Live camera access is not available in the hosted environment
|
| 463 |
+
- This is a security restriction of Hugging Face Spaces
|
| 464 |
+
- To use camera features, you need to run this app locally on your machine
|
| 465 |
+
|
| 466 |
+
You can still use the image upload option for face detection.
|
| 467 |
+
""")
|
| 468 |
+
|
| 469 |
+
st.info("To run locally:")
|
| 470 |
+
st.code("""
|
| 471 |
+
1. Clone the repository
|
| 472 |
+
2. Install requirements: pip install -r requirements.txt
|
| 473 |
+
3. Run: streamlit run streamlit_app.py
|
| 474 |
+
""")
|
| 475 |
+
return None
|
| 476 |
+
|
| 477 |
+
cap = cv2.VideoCapture(0)
|
| 478 |
+
if not cap.isOpened():
|
| 479 |
+
st.error("Could not access the camera. Make sure it's connected and not being used by another application.")
|
| 480 |
+
return None
|
| 481 |
+
return cap
|
| 482 |
+
except Exception as e:
|
| 483 |
+
st.error(f"Error initializing camera: {str(e)}")
|
| 484 |
+
return None
|
| 485 |
+
|
| 486 |
if app_mode == "About":
|
| 487 |
st.markdown("""
|
| 488 |
## About This App
|
|
|
|
| 2177 |
if st.session_state.recognition_camera_running:
|
| 2178 |
try:
|
| 2179 |
st.info("Camera activated. Processing video in real-time...")
|
| 2180 |
+
cap = init_camera()
|
| 2181 |
+
if cap is not None:
|
| 2182 |
+
try:
|
| 2183 |
+
# Process video frames
|
| 2184 |
+
pass
|
| 2185 |
+
finally:
|
| 2186 |
+
cap.release()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2187 |
except Exception as e:
|
| 2188 |
st.error(str(e))
|
| 2189 |
st.session_state.recognition_camera_running = False
|