import os import subprocess import glob import gradio as gr from gradio.components import Gallery, Video, Textbox from classificatsion_video_demo import process def get_car_numbers(result_folder): # change current working directory to binare/linux/mu gdfg current_dir = os.getcwd() os.chdir("binaries/linux/x86_64") # construct and run the command # command = "python ../../../python/setup.py build_ext --inplace -v" # process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE) command = "PYTHONPATH=$PYTHONPATH:.:../../../python LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH python ../../../scripts/alpr/license_plate_recognizer.py --image ../../../"+result_folder+" --assets ../../../assets" process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE) # send newline character to standard input process.communicate(input='\n'.encode()) # wait for the subprocess to exit process.wait() os.chdir(current_dir) return 0 def predict(video_path): """ Gradio interface orqali yuklab olingan videodan problem framelarni ajratib olinadi va resultat sifatida Galleryga chiqariladi :param video_path: :return: file """ # Your image processing code here # print(video_path) _path = "assets/result_imgs" images = glob.glob(f'{_path}/*.jpg') for image in images: os.remove(image) problem, good, result = process(video_path) images = glob.glob(f'{_path}/*.jpg') get_car_numbers(result) # # selected_images = [images[0],images[len(images)//2],images[-1]] return problem+good, problem, good,images # return 0, 0, 0, images my_example = [ # ['video/vid_39_1284-2_1202.mp4'] # ['video/vid_39_1284-2_1174.mp4'] ] my_title = "Video Klassifikatsiya" my_description = "128-4 qoida `To’xtash chizig’ini bosish` bo'yicha video analiz" all_frame = Textbox(label="Umumiy framelar soni") problem_frame = Textbox(label="Muammoli framelar soni") good_frame = Textbox(label="Muammosiz framelar soni") problem_frames = Gallery(label="Muammoli rasmlar", elem_id="gallery").style( grid=[3], height="auto" ) input_video = Video(label="Kiruvchi video") # Create input video component gr.Interface(fn=predict, inputs=input_video, outputs=[all_frame,problem_frame,good_frame,problem_frames], title=my_title, examples=my_example, description=my_description).launch()