Spaces:
Runtime error
Runtime error
Update streamlit_app.py
Browse files- streamlit_app.py +29 -27
streamlit_app.py
CHANGED
|
@@ -359,42 +359,44 @@ else:
|
|
| 359 |
st.write("Connect a live camera to detect solar panel defects in real-time.")
|
| 360 |
|
| 361 |
if WEBRTC_AVAILABLE and model:
|
| 362 |
-
|
| 363 |
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
|
| 368 |
-
|
| 369 |
-
|
|
|
|
| 370 |
|
| 371 |
-
|
| 372 |
-
|
|
|
|
| 373 |
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
for r in results:
|
| 377 |
-
annotated_img = r.plot() # YOLO's plot method returns annotated image
|
| 378 |
-
|
| 379 |
-
return frame.from_ndarray(annotated_img, format="bgr24")
|
| 380 |
|
| 381 |
webrtc_streamer(
|
| 382 |
-
key="
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
),
|
| 393 |
)
|
|
|
|
|
|
|
|
|
|
| 394 |
elif not WEBRTC_AVAILABLE:
|
| 395 |
-
st.error("
|
| 396 |
else:
|
| 397 |
-
st.
|
|
|
|
|
|
|
| 398 |
|
| 399 |
# ---------------- VIDEO ANALYSIS ----------------
|
| 400 |
elif menu == "Video Analysis":
|
|
|
|
| 359 |
st.write("Connect a live camera to detect solar panel defects in real-time.")
|
| 360 |
|
| 361 |
if WEBRTC_AVAILABLE and model:
|
| 362 |
+
import av # تأكد من إضافة av في ملف requirements.txt
|
| 363 |
|
| 364 |
+
def video_frame_callback(frame):
|
| 365 |
+
# تحويل الفريم إلى مصفوفة Numpy (BGR)
|
| 366 |
+
img = frame.to_ndarray(format="bgr24")
|
| 367 |
|
| 368 |
+
# إجراء الكشف باستخدام الموديل
|
| 369 |
+
# نستخدم الموديل مباشرة لتحسين الأداء
|
| 370 |
+
results = model(img, conf=0.5, verbose=False)
|
| 371 |
|
| 372 |
+
# رسم المربعات والنتائج (Annotate)
|
| 373 |
+
# YOLOv8 توفر ميزة .plot() التي تعود بالصورة مرسوم عليها النتائج
|
| 374 |
+
annotated_img = results[0].plot()
|
| 375 |
|
| 376 |
+
# إعادة الفريم إلى تنسيق الفيديو المطلوب للمتصفح
|
| 377 |
+
return av.VideoFrame.from_ndarray(annotated_img, format="bgr24")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
|
| 379 |
webrtc_streamer(
|
| 380 |
+
key="solar-guard-live",
|
| 381 |
+
video_frame_callback=video_frame_callback,
|
| 382 |
+
rtc_configuration={
|
| 383 |
+
"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
|
| 384 |
+
},
|
| 385 |
+
media_stream_constraints={
|
| 386 |
+
"video": True,
|
| 387 |
+
"audio": False,
|
| 388 |
+
},
|
| 389 |
+
async_processing=True, # لتحسين سرعة الفيديو
|
|
|
|
| 390 |
)
|
| 391 |
+
|
| 392 |
+
st.info("💡 اضغط على Start لبدء تشغيل الكاميرا. قد يطلب المتصفح إذن الوصول للكاميرا.")
|
| 393 |
+
|
| 394 |
elif not WEBRTC_AVAILABLE:
|
| 395 |
+
st.error("⚠️ مكتبة streamlit_webrtc غير مثبتة. تأكد من إضافتها لملف requirements.txt")
|
| 396 |
else:
|
| 397 |
+
st.error("⚠️ الموديل (best.pt) لم يتم تحميله بشكل صحيح. تأكد من رفعه باستخدام Git LFS كما ذكرنا.")
|
| 398 |
+
|
| 399 |
+
|
| 400 |
|
| 401 |
# ---------------- VIDEO ANALYSIS ----------------
|
| 402 |
elif menu == "Video Analysis":
|