File size: 3,234 Bytes
2fee509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import gradio as gr
import os
import pprint


dir_models3D = "assets/windmill/models3D/"
dir_images = "assets/windmill/images/"
dir_videos = "assets/windmill/videos/"


model3D_names = [f for f in os.listdir(dir_models3D) if f.endswith('.gltf') or f.endswith('.obj') or f.endswith('.glb') or f.endswith('.splat')]
model3D_files = [dir_models3D + n for n in model3D_names]

images_names = [f for f in os.listdir(dir_images) if f.endswith('.jpg') or f.endswith('.png')]
images_files = [(dir_images + n , n) for n in images_names]

video_names = [f for f in os.listdir(dir_videos) if f.endswith('.mp4') or f.endswith('.avi')]
video_files = [dir_videos + n for n in video_names]



print(model3D_files)
print(images_files)
print(video_files)


DESCRIPTION = """## PROJET MOULIN SIMON (Visualisation des medias) """

css = '''
.gradio-container {max-width: 1280px !important; height:90%;}
#gallery { height: 90% !important; } /* Adjusted for padding/margin if any */
h1{text-align:center}
'''


with gr.Blocks(analytics_enabled=False , css=css, theme="bethecloud/storj_theme" , elem_id='gradio-container') as demo:
    gr.Markdown(DESCRIPTION)
    
    with gr.Tab("Modèles 3D"):
        
        model_viewer = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model" , interactive=False , value=model3D_files[0])

        with gr.Row(visible=True):
        
            model_selection = gr.Radio(
                show_label=True,
                container=True,
                interactive=True,
                choices=model3D_names,
                value=model3D_names[0],
                label="Selectionner un modèle 3D :",
            )

        def load_mesh(model_name):
            model_file = dir_models3D + model_name
            print(f'LOADING MODEL: {model_file}')
            # model_viewer.update(value=model_file)
            return model_file
            
        model_selection.change(fn=load_mesh, inputs=model_selection, outputs=model_viewer)

    with gr.Tab("Images"):
        image_viewer = gr.Gallery(label="Generated images", 
                                  show_label=False, 
                                  elem_id='gallery', 
                                  columns=[3], 
                                  rows=[1], 
                                  object_fit="cover", 
                                  interactive=False,
                                  value=images_files
                                  )

    with gr.Tab("Videos"):
    
        video_viewer = gr.Video(interactive = False, value=video_files[0])

        with gr.Row(visible=True):
        
            video_selection = gr.Radio(
                show_label=True,
                container=True,
                interactive=True,
                choices=video_names,
                value=video_names[0],
                label="Selectionner une video:",
            )

        def load_video(video_name):
            video_file = dir_videos + video_name
            print(f'LOADING VIDEO: {video_file}')
            return video_file
            
        video_selection.change(fn=load_video, inputs=video_selection, outputs=video_viewer)

    
if __name__ == "__main__":
    demo.launch(debug=True, show_api=True)