Spaces:
Sleeping
Sleeping
efraim1011
commited on
Commit
•
207f867
1
Parent(s):
6e99ad0
Errors fixed
Browse files
app.py
CHANGED
@@ -98,10 +98,8 @@ create_directory(directory_path=RESULTS)
|
|
98 |
|
99 |
def process_categories(categories: str) -> List[str]:
|
100 |
# Traduzindo as palavras do português para o inglês
|
101 |
-
translator = Translator(from_lang="pt", to_lang="en")
|
102 |
-
translation = translator.translate(categories)
|
103 |
|
104 |
-
return [category.strip() for category in
|
105 |
|
106 |
|
107 |
def annotate_image(
|
@@ -210,6 +208,7 @@ def process_video(
|
|
210 |
sink.write_frame(frame)
|
211 |
return result_file_path
|
212 |
|
|
|
213 |
def process_image_real_time(
|
214 |
input_image: np.ndarray,
|
215 |
categories: str = "safety helmet, safety glasses, hearing protectors, protective masks, safety shoes, protective gloves, seat belt, person, bicycle, car, motorcycle, airplane, dining table, bus, train, truck, boat, parking meter, bench, bird, cat, dog, horse, elephant, bear, zebra, giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports ball, kite, baseball bat, baseball glove, skateboard, surfboard, tennis racket, bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange, donut, cake, chair, couch, potted plant, bed, toilet, tv, laptop, mouse, remote, keyboard, cell phone, microwave, oven, toaster, sink, refrigerator, book, clock, vase, teddy bear, hair drier, toothbrush",
|
@@ -217,9 +216,9 @@ def process_image_real_time(
|
|
217 |
iou_threshold: float = 0.5,
|
218 |
# with_segmentation: bool = True,
|
219 |
with_confidence: bool = False,
|
220 |
-
with_class_agnostic_nms: bool = False,
|
|
|
221 |
# cleanup of old video files
|
222 |
-
|
223 |
remove_files_older_than(RESULTS, 30)
|
224 |
|
225 |
categories = process_categories(categories)
|
@@ -247,7 +246,6 @@ def process_image_real_time(
|
|
247 |
return cv2.cvtColor(output_image, cv2.COLOR_BGR2RGB)
|
248 |
|
249 |
|
250 |
-
|
251 |
confidence_threshold_component = gr.Slider(
|
252 |
minimum=0,
|
253 |
maximum=1.0,
|
@@ -408,6 +406,6 @@ with gr.Blocks() as demo:
|
|
408 |
],
|
409 |
outputs=output_video_component
|
410 |
)
|
411 |
-
input_real_time_component.change(fn=process_image_real_time,inputs=input_real_time_component, outputs=output_real_time_component)
|
412 |
|
413 |
demo.launch(debug=False, show_error=True, max_threads=1, share=True)
|
|
|
98 |
|
99 |
def process_categories(categories: str) -> List[str]:
|
100 |
# Traduzindo as palavras do português para o inglês
|
|
|
|
|
101 |
|
102 |
+
return [category.strip() for category in categories.split(',')]
|
103 |
|
104 |
|
105 |
def annotate_image(
|
|
|
208 |
sink.write_frame(frame)
|
209 |
return result_file_path
|
210 |
|
211 |
+
|
212 |
def process_image_real_time(
|
213 |
input_image: np.ndarray,
|
214 |
categories: str = "safety helmet, safety glasses, hearing protectors, protective masks, safety shoes, protective gloves, seat belt, person, bicycle, car, motorcycle, airplane, dining table, bus, train, truck, boat, parking meter, bench, bird, cat, dog, horse, elephant, bear, zebra, giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports ball, kite, baseball bat, baseball glove, skateboard, surfboard, tennis racket, bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange, donut, cake, chair, couch, potted plant, bed, toilet, tv, laptop, mouse, remote, keyboard, cell phone, microwave, oven, toaster, sink, refrigerator, book, clock, vase, teddy bear, hair drier, toothbrush",
|
|
|
216 |
iou_threshold: float = 0.5,
|
217 |
# with_segmentation: bool = True,
|
218 |
with_confidence: bool = False,
|
219 |
+
with_class_agnostic_nms: bool = False,
|
220 |
+
) -> np.ndarray:
|
221 |
# cleanup of old video files
|
|
|
222 |
remove_files_older_than(RESULTS, 30)
|
223 |
|
224 |
categories = process_categories(categories)
|
|
|
246 |
return cv2.cvtColor(output_image, cv2.COLOR_BGR2RGB)
|
247 |
|
248 |
|
|
|
249 |
confidence_threshold_component = gr.Slider(
|
250 |
minimum=0,
|
251 |
maximum=1.0,
|
|
|
406 |
],
|
407 |
outputs=output_video_component
|
408 |
)
|
409 |
+
input_real_time_component.change(fn=process_image_real_time, inputs=input_real_time_component, outputs=output_real_time_component)
|
410 |
|
411 |
demo.launch(debug=False, show_error=True, max_threads=1, share=True)
|