Spaces:
Sleeping
Sleeping
app.py
CHANGED
@@ -5,6 +5,7 @@ import pprint
|
|
5 |
import sys
|
6 |
from pathlib import Path
|
7 |
from collections import OrderedDict
|
|
|
8 |
|
9 |
|
10 |
print('\n\n================================ START')
|
@@ -55,21 +56,73 @@ css = '''
|
|
55 |
#gallery { height: 90% !important; } /* Adjusted for padding/margin if any */
|
56 |
h1{text-align:center}
|
57 |
'''
|
58 |
-
|
59 |
head = '''
|
60 |
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js"></script>
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
def read_text_file(path:str)->str :
|
64 |
with open(path, 'r', encoding='utf-8') as file:
|
65 |
content = file.read()
|
66 |
return content
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
#print(head)
|
70 |
#head = head.replace('BASE_URL_3D' , BASE_URL + dir_models3D )
|
71 |
#print(head)
|
72 |
-
|
73 |
with gr.Blocks(analytics_enabled=False , head=head , css=css, theme="bethecloud/storj_theme" , elem_id='gradio-container') as demo:
|
74 |
|
75 |
|
@@ -84,19 +137,35 @@ with gr.Blocks(analytics_enabled=False , head=head , css=css, theme="bethecloud/
|
|
84 |
gr.HTML(f'''<div style="width:100%; text-align:left"><img src="{BASE_URL}assets/images/banner-dugrainaupain.jpg" style="display: inline-block;"></div>''')
|
85 |
|
86 |
with gr.Tab("LE PROJET....."):
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
with gr.Tab("Avant/Après"):
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
|
|
100 |
print(f'{BASE_URL}assets/images/before-after/moulin-insitu-1-_1610534-BEFORE.jpg')
|
101 |
print(f'{BASE_URL}assets/images/before-after/moulin-insitu-1-_1610534-AFTER.jpg')
|
102 |
|
|
|
5 |
import sys
|
6 |
from pathlib import Path
|
7 |
from collections import OrderedDict
|
8 |
+
from PIL import Image
|
9 |
|
10 |
|
11 |
print('\n\n================================ START')
|
|
|
56 |
#gallery { height: 90% !important; } /* Adjusted for padding/margin if any */
|
57 |
h1{text-align:center}
|
58 |
'''
|
59 |
+
|
60 |
head = '''
|
61 |
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js"></script>
|
62 |
+
<script defer src="https://cdn.jsdelivr.net/npm/img-comparison-slider@8/dist/index.js"></script>
|
63 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/img-comparison-slider@8/dist/styles.css"/>
|
64 |
+
<style>
|
65 |
+
.custom-animated-handle {
|
66 |
+
transition: transform 0.2s;
|
67 |
+
}
|
68 |
|
69 |
+
.slider-with-animated-handle:hover .custom-animated-handle {
|
70 |
+
transform: scale(1.2);
|
71 |
+
}
|
72 |
+
|
73 |
+
h1, h2 {
|
74 |
+
color: #0056b3;
|
75 |
+
# padding-bottom:10px;
|
76 |
+
padding-top:10px;
|
77 |
+
}
|
78 |
+
p {
|
79 |
+
margin: 1em 0;
|
80 |
+
}
|
81 |
+
.highlight {
|
82 |
+
color: #d9534f;
|
83 |
+
font-weight: bold;
|
84 |
+
}
|
85 |
+
.emphasis {
|
86 |
+
color: #5cb85c;
|
87 |
+
font-style: italic;
|
88 |
+
}
|
89 |
+
</style>
|
90 |
+
'''
|
91 |
+
|
92 |
def read_text_file(path:str)->str :
|
93 |
with open(path, 'r', encoding='utf-8') as file:
|
94 |
content = file.read()
|
95 |
return content
|
96 |
|
97 |
+
def read_PIL_images(filenames):
|
98 |
+
images = []
|
99 |
+
for filename in filenames:
|
100 |
+
try:
|
101 |
+
print(f'Loading {filename}......')
|
102 |
+
img = Image.open(filename)
|
103 |
+
images.append(img)
|
104 |
+
print(f'Loaded {filename}')
|
105 |
+
except Exception as e:
|
106 |
+
print(f"Error opening image {filename}: {e}")
|
107 |
+
return images
|
108 |
+
|
109 |
+
def build_comparison_slider(before_url , after_url):
|
110 |
+
# @see https://img-comparison-slider.sneas.io/examples.html#always-show
|
111 |
+
html = f'''
|
112 |
+
<img-comparison-slider class="slider-with-animated-handle" style="max-width:500px; --divider-width: 4px; --divider-color: #ff0000;">
|
113 |
+
<img slot="first" width="100%" src="{before_url}" />
|
114 |
+
<img slot="second" width="100%" src="{after_url}" />
|
115 |
+
<svg slot="handle" class="custom-animated-handle" xmlns="http://www.w3.org/2000/svg" width="100" viewBox="-8 -3 16 6">
|
116 |
+
<path stroke="#fff" d="M -5 -2 L -7 0 L -5 2 M -5 -2 L -5 2 M 5 -2 L 7 0 L 5 2 M 5 -2 L 5 2" stroke-width="1" fill="#fff" vector-effect="non-scaling-stroke"></path>
|
117 |
+
</svg>
|
118 |
+
</img-comparison-slider>'''
|
119 |
+
|
120 |
+
return html
|
121 |
|
122 |
#print(head)
|
123 |
#head = head.replace('BASE_URL_3D' , BASE_URL + dir_models3D )
|
124 |
#print(head)
|
125 |
+
|
126 |
with gr.Blocks(analytics_enabled=False , head=head , css=css, theme="bethecloud/storj_theme" , elem_id='gradio-container') as demo:
|
127 |
|
128 |
|
|
|
137 |
gr.HTML(f'''<div style="width:100%; text-align:left"><img src="{BASE_URL}assets/images/banner-dugrainaupain.jpg" style="display: inline-block;"></div>''')
|
138 |
|
139 |
with gr.Tab("LE PROJET....."):
|
140 |
+
with gr.Row():
|
141 |
+
with gr.Column(scale=1):
|
142 |
+
before = BASE_URL + 'assets/images/before-after/moulin-insitu-1-_1610534-BEFORE.jpg'
|
143 |
+
after = BASE_URL + 'assets/images/before-after/moulin-insitu-1-_1610534-AFTER.jpg'
|
144 |
+
gr.HTML(build_comparison_slider(before , after)
|
145 |
+
|
146 |
+
with gr.Column(scale=1):
|
147 |
+
gr.HTML(read_text_file("assets/html/intro.txt"))
|
148 |
|
149 |
with gr.Tab("Avant/Après"):
|
150 |
|
151 |
+
with gr.Row():
|
152 |
+
|
153 |
+
before_after_1= gr.HTML(f'''
|
154 |
+
<img-comparison-slider hover="hover" class="slider-with-animated-handle" style="max-width:500px; --divider-width: 4px; --divider-color: #ff0000;">
|
155 |
+
<img slot="first" width="100%" src="{BASE_URL}assets/images/before-after/moulin-insitu-1-_1610534-BEFORE.jpg" />
|
156 |
+
<img slot="second" width="100%" src="{BASE_URL}assets/images/before-after/moulin-insitu-1-_1610534-AFTER.jpg" />
|
157 |
+
<svg slot="handle" class="custom-animated-handle" xmlns="http://www.w3.org/2000/svg" width="100" viewBox="-8 -3 16 6">
|
158 |
+
<path stroke="#fff" d="M -5 -2 L -7 0 L -5 2 M -5 -2 L -5 2 M 5 -2 L 7 0 L 5 2 M 5 -2 L 5 2" stroke-width="1" fill="#fff" vector-effect="non-scaling-stroke"></path>
|
159 |
+
</svg>
|
160 |
+
</img-comparison-slider>''')
|
161 |
+
|
162 |
+
before_after_2 = gr.HTML(f'''
|
163 |
+
<img-comparison-slider hover="hover" class="slider-with-animated-handle" style="max-width:500px; --divider-width: 4px; --divider-color: #ff0000;">
|
164 |
+
<img slot="first" width="100%" src="{BASE_URL}assets/images/before-after/moulin-insitu-1-_1610534-BEFORE.jpg" />
|
165 |
+
<img slot="second" width="100%" src="{BASE_URL}assets/images/before-after/moulin-insitu-1-_1610534-AFTER.jpg" />
|
166 |
+
</img-comparison-slider>''')
|
167 |
|
168 |
+
|
169 |
print(f'{BASE_URL}assets/images/before-after/moulin-insitu-1-_1610534-BEFORE.jpg')
|
170 |
print(f'{BASE_URL}assets/images/before-after/moulin-insitu-1-_1610534-AFTER.jpg')
|
171 |
|
assets/html/intro.txt
CHANGED
@@ -16,7 +16,7 @@
|
|
16 |
.container {
|
17 |
max-width: 800px;
|
18 |
margin: auto;
|
19 |
-
padding:
|
20 |
background-color: #fff;
|
21 |
}
|
22 |
h1, h2 {
|
@@ -39,7 +39,7 @@
|
|
39 |
</head>
|
40 |
<body>
|
41 |
<div class="container">
|
42 |
-
<h1
|
43 |
<p><span class="highlight">Belle-Île-en-Mer</span>, joyau de la Bretagne, s'apprête à accueillir un projet ambitieux et unique en son genre : la construction d'un moulin à vent destiné à moudre du blé et à produire de la farine. Cette initiative est portée par l'association à but non lucratif <span class="highlight">"DU GRAIN AU PAIN"</span>.</p>
|
44 |
|
45 |
<h2>Un Projet pour Revitaliser l'Artisanat Local</h2>
|
|
|
16 |
.container {
|
17 |
max-width: 800px;
|
18 |
margin: auto;
|
19 |
+
padding: 0px;
|
20 |
background-color: #fff;
|
21 |
}
|
22 |
h1, h2 {
|
|
|
39 |
</head>
|
40 |
<body>
|
41 |
<div class="container">
|
42 |
+
<h1>Énergie Solidaire sur Belle-Île-en-Mer</h1>
|
43 |
<p><span class="highlight">Belle-Île-en-Mer</span>, joyau de la Bretagne, s'apprête à accueillir un projet ambitieux et unique en son genre : la construction d'un moulin à vent destiné à moudre du blé et à produire de la farine. Cette initiative est portée par l'association à but non lucratif <span class="highlight">"DU GRAIN AU PAIN"</span>.</p>
|
44 |
|
45 |
<h2>Un Projet pour Revitaliser l'Artisanat Local</h2>
|
assets/images/before-after/moulin-insitu-1-_1610534-schema-BEFORE.jpg
ADDED