File size: 2,469 Bytes
908e980
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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()