Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
@@ -37,11 +37,24 @@ def load_detector(model_name):
|
|
37 |
@spaces.GPU
|
38 |
def process_webcam(image, model_choice, confidence_threshold):
|
39 |
"""Traite l'image de la webcam"""
|
40 |
-
print(f"🎥 Frame reçue - Type: {type(image)}")
|
41 |
|
42 |
if image is None:
|
43 |
-
print("❌ Image None reçue")
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
try:
|
47 |
# S'assurer qu'on a une image PIL
|
@@ -138,23 +151,30 @@ def draw_detections(image, detections):
|
|
138 |
|
139 |
return img_copy
|
140 |
|
141 |
-
# Interface
|
142 |
demo = gr.Interface(
|
143 |
fn=process_webcam,
|
144 |
inputs=[
|
145 |
-
gr.Image(
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
gr.Dropdown(
|
147 |
choices=list(REALTIME_MODELS.keys()),
|
148 |
value="YOLOS Tiny (ultra-rapide)",
|
149 |
label="Modèle"
|
150 |
),
|
151 |
-
gr.Slider(0.1, 1.0, 0.
|
152 |
],
|
153 |
-
outputs=gr.Image(streaming=True, type="pil"),
|
154 |
live=True,
|
155 |
title="🎥 Détection Live",
|
156 |
-
description="
|
157 |
-
allow_flagging="never"
|
|
|
158 |
)
|
159 |
|
160 |
if __name__ == "__main__":
|
|
|
37 |
@spaces.GPU
|
38 |
def process_webcam(image, model_choice, confidence_threshold):
|
39 |
"""Traite l'image de la webcam"""
|
40 |
+
print(f"🎥 Frame reçue - Type: {type(image)}, Shape: {getattr(image, 'size', 'N/A')}")
|
41 |
|
42 |
if image is None:
|
43 |
+
print("❌ Image None reçue - webcam pas encore initialisée")
|
44 |
+
# Retourner une image d'attente
|
45 |
+
waiting_img = Image.new('RGB', (640, 480), color='#1f2937')
|
46 |
+
draw = ImageDraw.Draw(waiting_img)
|
47 |
+
try:
|
48 |
+
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 32)
|
49 |
+
except:
|
50 |
+
font = ImageFont.load_default()
|
51 |
+
|
52 |
+
text = "🎥 En attente de la webcam..."
|
53 |
+
bbox = draw.textbbox((0, 0), text, font=font)
|
54 |
+
x = (640 - bbox[2]) // 2
|
55 |
+
y = (480 - bbox[3]) // 2
|
56 |
+
draw.text((x, y), text, fill='white', font=font)
|
57 |
+
return waiting_img
|
58 |
|
59 |
try:
|
60 |
# S'assurer qu'on a une image PIL
|
|
|
151 |
|
152 |
return img_copy
|
153 |
|
154 |
+
# Interface avec configuration webcam améliorée
|
155 |
demo = gr.Interface(
|
156 |
fn=process_webcam,
|
157 |
inputs=[
|
158 |
+
gr.Image(
|
159 |
+
sources=["webcam"],
|
160 |
+
streaming=True,
|
161 |
+
type="pil",
|
162 |
+
mirror_webcam=False,
|
163 |
+
show_download_button=False
|
164 |
+
),
|
165 |
gr.Dropdown(
|
166 |
choices=list(REALTIME_MODELS.keys()),
|
167 |
value="YOLOS Tiny (ultra-rapide)",
|
168 |
label="Modèle"
|
169 |
),
|
170 |
+
gr.Slider(0.1, 1.0, 0.1, step=0.1, label="Confiance")
|
171 |
],
|
172 |
+
outputs=gr.Image(streaming=True, type="pil", show_download_button=False),
|
173 |
live=True,
|
174 |
title="🎥 Détection Live",
|
175 |
+
description="⚠️ Cliquez sur l'icône webcam et autorisez l'accès pour commencer",
|
176 |
+
allow_flagging="never",
|
177 |
+
flagging_mode="never"
|
178 |
)
|
179 |
|
180 |
if __name__ == "__main__":
|