Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,53 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
3 |
import pprint
|
|
|
|
|
|
|
4 |
|
|
|
|
|
|
|
5 |
BASE_URL = "https://huggingface.co/spaces/menorki/projet-moulin-belle-ile/resolve/main/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
dir_models3D = "assets/windmill/models3D/"
|
8 |
dir_images = "assets/windmill/images/"
|
9 |
dir_videos = "assets/windmill/videos/"
|
10 |
|
|
|
11 |
|
12 |
-
model3D_names = [f for f in os.listdir(dir_models3D) if f.endswith('.gltf') or f.endswith('.obj') or f.endswith('.glb')
|
13 |
-
model3D_files = [BASE_URL + dir_models3D +
|
14 |
|
15 |
images_names = [f for f in os.listdir(dir_images) if f.endswith('.jpg') or f.endswith('.png')]
|
16 |
-
images_files = [(BASE_URL + dir_images +
|
17 |
|
18 |
video_names = [f for f in os.listdir(dir_videos) if f.endswith('.mp4') or f.endswith('.avi')]
|
19 |
-
video_files = [BASE_URL + dir_videos +
|
20 |
-
|
21 |
|
22 |
|
23 |
-
print(model3D_files)
|
24 |
-
print(images_files)
|
25 |
-
print(video_files)
|
26 |
|
27 |
|
28 |
-
DESCRIPTION = """## PROJET MOULIN SIMON
|
29 |
|
30 |
css = '''
|
31 |
.gradio-container {max-width: 1280px !important; height:90%;}
|
@@ -33,10 +55,60 @@ css = '''
|
|
33 |
h1{text-align:center}
|
34 |
'''
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
with gr.Blocks(analytics_enabled=False , css=css, theme="bethecloud/storj_theme" , elem_id='gradio-container') as demo:
|
|
|
38 |
gr.Markdown(DESCRIPTION)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
with gr.Tab("Modèles 3D"):
|
41 |
|
42 |
model_viewer = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model" , interactive=False , value=model3D_files[0])
|
@@ -59,21 +131,11 @@ with gr.Blocks(analytics_enabled=False , css=css, theme="bethecloud/storj_theme"
|
|
59 |
return model_file
|
60 |
|
61 |
model_selection.change(fn=load_mesh, inputs=model_selection, outputs=model_viewer)
|
62 |
-
|
63 |
-
|
64 |
-
image_viewer = gr.Gallery(label="Generated images",
|
65 |
-
show_label=False,
|
66 |
-
elem_id='gallery',
|
67 |
-
columns=[3],
|
68 |
-
rows=[1],
|
69 |
-
object_fit="cover",
|
70 |
-
interactive=False,
|
71 |
-
value=images_files,
|
72 |
-
)
|
73 |
-
|
74 |
with gr.Tab("Videos"):
|
75 |
|
76 |
-
video_viewer = gr.Video(interactive
|
77 |
|
78 |
with gr.Row(visible=True):
|
79 |
|
@@ -95,4 +157,4 @@ with gr.Blocks(analytics_enabled=False , css=css, theme="bethecloud/storj_theme"
|
|
95 |
|
96 |
|
97 |
if __name__ == "__main__":
|
98 |
-
demo.launch(debug=
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_imageslider import ImageSlider
|
3 |
import os
|
4 |
import pprint
|
5 |
+
import sys
|
6 |
+
from pathlib import Path
|
7 |
+
from collections import OrderedDict
|
8 |
|
9 |
+
print('\n\n================================ START')
|
10 |
+
|
11 |
+
SEP = os.path.sep
|
12 |
BASE_URL = "https://huggingface.co/spaces/menorki/projet-moulin-belle-ile/resolve/main/"
|
13 |
+
BASE_PATH = Path(__file__).resolve().parent
|
14 |
+
BASE_DIR = str(BASE_PATH) + SEP
|
15 |
+
IN_SPACE = os.environ.get("SPACE_AUTHOR_NAME") in ["menorki"]
|
16 |
+
|
17 |
+
TMP_PATH = BASE_PATH / 'gradio_tmp'
|
18 |
+
TMP_DIR = str(TMP_PATH) + SEP
|
19 |
+
#if TMP_DIR.exists():
|
20 |
+
# shutil.rmtree(str(TMP_DIR))
|
21 |
+
TMP_PATH.mkdir(exist_ok=True, parents=True)
|
22 |
+
os.environ['GRADIO_TEMP_DIR'] = TMP_DIR
|
23 |
+
|
24 |
+
print(f"BASE_URL: {BASE_URL}")
|
25 |
+
print(f"BASE_DIR: {BASE_DIR}")
|
26 |
+
print(f"TMP_DIR: {TMP_DIR}")
|
27 |
+
print(f"IN_SPACE: {IN_SPACE}")
|
28 |
|
29 |
dir_models3D = "assets/windmill/models3D/"
|
30 |
dir_images = "assets/windmill/images/"
|
31 |
dir_videos = "assets/windmill/videos/"
|
32 |
|
33 |
+
# gr.set_static_paths(paths=[f"{BASE_DIR}assets/windmill"])
|
34 |
|
35 |
+
model3D_names = [f for f in os.listdir(dir_models3D) if f.endswith('.gltf') or f.endswith('.obj') or f.endswith('.glb')]
|
36 |
+
model3D_files = [BASE_URL + dir_models3D + name for name in model3D_names]
|
37 |
|
38 |
images_names = [f for f in os.listdir(dir_images) if f.endswith('.jpg') or f.endswith('.png')]
|
39 |
+
images_files = [(BASE_URL + dir_images + name , name) for name in images_names]
|
40 |
|
41 |
video_names = [f for f in os.listdir(dir_videos) if f.endswith('.mp4') or f.endswith('.avi')]
|
42 |
+
video_files = [BASE_URL + dir_videos + name for name in video_names]
|
|
|
43 |
|
44 |
|
45 |
+
#print(model3D_files)
|
46 |
+
#print(images_files)
|
47 |
+
#print(video_files)
|
48 |
|
49 |
|
50 |
+
DESCRIPTION = """## PROJET MOULIN SIMON """
|
51 |
|
52 |
css = '''
|
53 |
.gradio-container {max-width: 1280px !important; height:90%;}
|
|
|
55 |
h1{text-align:center}
|
56 |
'''
|
57 |
|
58 |
+
head = '''
|
59 |
+
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js"></script>
|
60 |
+
'''
|
61 |
+
|
62 |
+
#print(head)
|
63 |
+
#head = head.replace('BASE_URL_3D' , BASE_URL + dir_models3D )
|
64 |
+
#print(head)
|
65 |
|
66 |
+
with gr.Blocks(analytics_enabled=False , head=head , css=css, theme="bethecloud/storj_theme" , elem_id='gradio-container') as demo:
|
67 |
+
|
68 |
gr.Markdown(DESCRIPTION)
|
69 |
+
|
70 |
+
with gr.Tab("Images"):
|
71 |
+
image_viewer = gr.Gallery(label="Generated images",
|
72 |
+
show_label=False,
|
73 |
+
elem_id='gallery',
|
74 |
+
columns=[3],
|
75 |
+
rows=[1],
|
76 |
+
object_fit="cover",
|
77 |
+
interactive=False,
|
78 |
+
value=images_files,
|
79 |
+
)
|
80 |
+
|
81 |
+
with gr.Tab("Modèles 3D"):
|
82 |
|
83 |
+
viewer_html = '''<div id="google-3D-viewer-container" style="width:1024px; height:600px;" style="flex: 1; display: flex; justify-content: center; align-items: center;">
|
84 |
+
<model-viewer id="google-3D-viewer" style="width: 100%; height: 100%;" src="DEFAULT_MODEL_URL" auto-rotate camera-controls></model-viewer>
|
85 |
+
</div>
|
86 |
+
'''
|
87 |
+
|
88 |
+
viewer_html = viewer_html.replace('DEFAULT_MODEL_URL' , BASE_URL + dir_models3D + model3D_names[0])
|
89 |
+
viewer_html = viewer_html.replace('BASE_URL_3D' , BASE_URL + dir_models3D)
|
90 |
+
# print(viewer_html)
|
91 |
+
|
92 |
+
google_viewer = gr.HTML(viewer_html)
|
93 |
+
|
94 |
+
with gr.Row(visible=True):
|
95 |
+
|
96 |
+
model_selection = gr.Radio(
|
97 |
+
show_label=True,
|
98 |
+
container=True,
|
99 |
+
interactive=True,
|
100 |
+
choices=model3D_names,
|
101 |
+
value=model3D_names[0],
|
102 |
+
label="Selectionner un modèle 3D :",
|
103 |
+
)
|
104 |
+
|
105 |
+
# js = f"(name) => document.getElementById('google-3D-viewer').src = '{BASE_URL + dir_models3D}' + name"
|
106 |
+
model_selection.change(fn=None,
|
107 |
+
inputs=model_selection,
|
108 |
+
outputs=None ,
|
109 |
+
js=f"(name) => document.getElementById('google-3D-viewer').src = '{BASE_URL + dir_models3D}' + name")
|
110 |
+
|
111 |
+
'''
|
112 |
with gr.Tab("Modèles 3D"):
|
113 |
|
114 |
model_viewer = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model" , interactive=False , value=model3D_files[0])
|
|
|
131 |
return model_file
|
132 |
|
133 |
model_selection.change(fn=load_mesh, inputs=model_selection, outputs=model_viewer)
|
134 |
+
'''
|
135 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
with gr.Tab("Videos"):
|
137 |
|
138 |
+
video_viewer = gr.Video(interactive=False, value=video_files[0])
|
139 |
|
140 |
with gr.Row(visible=True):
|
141 |
|
|
|
157 |
|
158 |
|
159 |
if __name__ == "__main__":
|
160 |
+
demo.launch(debug=not IN_SPACE, show_api=False)
|