menorki commited on
Commit
2fee509
·
1 Parent(s): 4907430

Add application file

Browse files
Files changed (1) hide show
  1. app.py +97 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import pprint
4
+
5
+
6
+ dir_models3D = "assets/windmill/models3D/"
7
+ dir_images = "assets/windmill/images/"
8
+ dir_videos = "assets/windmill/videos/"
9
+
10
+
11
+ 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')]
12
+ model3D_files = [dir_models3D + n for n in model3D_names]
13
+
14
+ images_names = [f for f in os.listdir(dir_images) if f.endswith('.jpg') or f.endswith('.png')]
15
+ images_files = [(dir_images + n , n) for n in images_names]
16
+
17
+ video_names = [f for f in os.listdir(dir_videos) if f.endswith('.mp4') or f.endswith('.avi')]
18
+ video_files = [dir_videos + n for n in video_names]
19
+
20
+
21
+
22
+ print(model3D_files)
23
+ print(images_files)
24
+ print(video_files)
25
+
26
+
27
+ DESCRIPTION = """## PROJET MOULIN SIMON (Visualisation des medias) """
28
+
29
+ css = '''
30
+ .gradio-container {max-width: 1280px !important; height:90%;}
31
+ #gallery { height: 90% !important; } /* Adjusted for padding/margin if any */
32
+ h1{text-align:center}
33
+ '''
34
+
35
+
36
+ with gr.Blocks(analytics_enabled=False , css=css, theme="bethecloud/storj_theme" , elem_id='gradio-container') as demo:
37
+ gr.Markdown(DESCRIPTION)
38
+
39
+ with gr.Tab("Modèles 3D"):
40
+
41
+ model_viewer = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model" , interactive=False , value=model3D_files[0])
42
+
43
+ with gr.Row(visible=True):
44
+
45
+ model_selection = gr.Radio(
46
+ show_label=True,
47
+ container=True,
48
+ interactive=True,
49
+ choices=model3D_names,
50
+ value=model3D_names[0],
51
+ label="Selectionner un modèle 3D :",
52
+ )
53
+
54
+ def load_mesh(model_name):
55
+ model_file = dir_models3D + model_name
56
+ print(f'LOADING MODEL: {model_file}')
57
+ # model_viewer.update(value=model_file)
58
+ return model_file
59
+
60
+ model_selection.change(fn=load_mesh, inputs=model_selection, outputs=model_viewer)
61
+
62
+ with gr.Tab("Images"):
63
+ image_viewer = gr.Gallery(label="Generated images",
64
+ show_label=False,
65
+ elem_id='gallery',
66
+ columns=[3],
67
+ rows=[1],
68
+ object_fit="cover",
69
+ interactive=False,
70
+ value=images_files
71
+ )
72
+
73
+ with gr.Tab("Videos"):
74
+
75
+ video_viewer = gr.Video(interactive = False, value=video_files[0])
76
+
77
+ with gr.Row(visible=True):
78
+
79
+ video_selection = gr.Radio(
80
+ show_label=True,
81
+ container=True,
82
+ interactive=True,
83
+ choices=video_names,
84
+ value=video_names[0],
85
+ label="Selectionner une video:",
86
+ )
87
+
88
+ def load_video(video_name):
89
+ video_file = dir_videos + video_name
90
+ print(f'LOADING VIDEO: {video_file}')
91
+ return video_file
92
+
93
+ video_selection.change(fn=load_video, inputs=video_selection, outputs=video_viewer)
94
+
95
+
96
+ if __name__ == "__main__":
97
+ demo.launch(debug=True, show_api=True)