menorki's picture
Add application file
2fee509
raw
history blame
3.23 kB
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)