a
    yµÿfC  ã                   @   sT   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ ddd„Ze	dkrPeƒ  dS )é    N)Úcheck_requirements)ÚGITHUB_ASSETS_STEMSc           "         sž  t dƒ ddl}ddlm} d}d}d}|jdd	d
d |j|dd |j|dd |j|dd |j" d}|j|dd W d  ƒ n1 s0    Y  |j d¡ |j 	dd¡}d}|dkr2|jj
dg d¢d}	|	dur@t |	 ¡ ¡}
d}t|dƒ}| |
 ¡ ¡ W d  ƒ n1 s"0    Y  d}n|dkr@d}dd„ tD ƒ}| rj| d|  d¡d ¡ |j 	d|¡}| d ¡0 || ¡ › dƒ} t| j ¡ ƒ‰ W d  ƒ n1 sº0    Y  | d!¡ |jjd"ˆ ˆ dd#… d$}‡ fd%d„|D ƒ}t|tƒst|ƒ}|j d&d'¡}t|j d(d)d*d+d,¡ƒ}t|j d-d)d*d.d,¡ƒ}| d/¡\}}| ¡ }| ¡ }|j ¡ }|j  d0¡rˆt! "|¡}| #¡ s | $d1¡ |  d2¡}| #¡ r€| ¡ \}}|sÔ| %d3¡ q€t& &¡ }|d4krü| j'||||dd5}n| ||||d6}|d  (¡ }t& &¡ } d7| |  }!| }|j|d8d9 |j|d8d9 |rl| )¡  t*j+ ,¡  | -¡  | .d:|!d;›¡ qª| )¡  t*j+ ,¡  t! /¡  dS )<zcRuns real-time object detection on video input using Ultralytics YOLOv8 in a Streamlit application.zstreamlit>=1.29.0r   N)ÚYOLOz-<style>MainMenu {visibility: hidden;}</style>a  <div><h1 style="color:#FF64DA; text-align:center; font-size:40px; 
                             font-family: 'Archivo', sans-serif; margin-top:-50px;margin-bottom:20px;">
                    Ultralytics YOLO Streamlit Application
                    </h1></div>u$  <div><h4 style="color:#042AFF; text-align:center; 
                    font-family: 'Archivo', sans-serif; margin-top:-15px; margin-bottom:50px;">
                    Experience real-time object detection on your webcam with the power of Ultralytics YOLO! ðŸš€</h4>
                    </div>zUltralytics Streamlit AppZwideÚauto)Z
page_titleZlayoutZinitial_sidebar_stateT)Zunsafe_allow_htmlz`https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svgéú   )ÚwidthzUser ConfigurationZVideo)ÚwebcamÚvideoÚ r	   zUpload Video File)Zmp4ZmovZaviZmkv)Útypezultralytics.mp4Úwbr   c                 S   s"   g | ]}|  d ¡r| dd¡‘qS )Zyolo11Zyolor   )Ú
startswithÚreplace)Ú.0Úx© r   úe/var/www/html/django/DPS/env/lib/python3.9/site-packages/ultralytics/solutions/streamlit_inference.pyÚ
<listcomp>F   ó    zinference.<locals>.<listcomp>z.ptZModelzModel is downloading...zModel loaded successfully!ZClassesé   )Údefaultc                    s   g | ]}ˆ   |¡‘qS r   )Úindex)r   Úoption©Zclass_namesr   r   r   R   r   zEnable Tracking)ÚYesZNozConfidence Thresholdg        g      ð?g      Ð?g{®Gáz„?zIoU ThresholdgÍÌÌÌÌÌÜ?é   ZStartzCould not open webcam.ZStopzTFailed to read frame from webcam. Please make sure the webcam is connected properly.r   )ÚconfÚiouÚclassesZpersist)r   r   r   é   ZBGR)ZchannelsZFPSz.2f)0r   Z	streamlitZultralyticsr   Zset_page_configÚmarkdownZsidebarÚimageÚtitleZ	selectboxZfile_uploaderÚioÚBytesIOÚreadÚopenÚwriter   ÚinsertÚsplitÚspinnerÚlowerÚlistÚnamesÚvaluesÚsuccessZmultiselectÚ
isinstanceÚradioÚfloatZsliderÚcolumnsÚemptyZbuttonÚcv2ZVideoCaptureZisOpenedÚerrorÚwarningÚtimeÚtrackZplotÚreleaseÚtorchÚcudaZempty_cacheÚstopZmetricZdestroyAllWindows)"ÚmodelÚstr   Zmenu_style_cfgZmain_title_cfgZsub_title_cfgZlogoÚsourceZvid_file_nameZvid_fileÚgZvid_locationÚoutZavailable_modelsZselected_modelZselected_classesZselected_indZ
enable_trkr   r   Zcol1Zcol2Z	org_frameZ	ann_frameZfps_displayZvideocaptureÚstop_buttonr/   ÚframeZ	prev_timeÚresultsZannotated_frameZ	curr_timeZfpsr   r   r   Ú	inference   s˜    ,þ

.
.










rF   Ú__main__)N)
r#   r8   r5   r;   Zultralytics.utils.checksr   Zultralytics.utils.downloadsr   rF   Ú__name__r   r   r   r   Ú<module>   s   
 