menorki commited on
Commit
185587d
·
1 Parent(s): 2cb712f
Files changed (4) hide show
  1. app.py +15 -4
  2. assets/images/banner-dugrainaupain.jpg +0 -0
  3. infos.txt +2 -0
  4. script.js +116 -0
app.py CHANGED
@@ -48,7 +48,7 @@ video_files = [BASE_URL + dir_videos + name for name in video_names]
48
  #print(video_files)
49
 
50
 
51
- DESCRIPTION = """## PROJET MOULIN SIMON """
52
 
53
  css = '''
54
  .gradio-container {max-width: 1280px !important; height:90%;}
@@ -60,10 +60,16 @@ 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
  #print(head)
64
  #head = head.replace('BASE_URL_3D' , BASE_URL + dir_models3D )
65
  #print(head)
66
-
67
  with gr.Blocks(analytics_enabled=False , head=head , css=css, theme="bethecloud/storj_theme" , elem_id='gradio-container') as demo:
68
 
69
 
@@ -72,8 +78,13 @@ with gr.Blocks(analytics_enabled=False , head=head , css=css, theme="bethecloud/
72
  # js_str = f.read()
73
  #demo.load(_js=js_str)
74
 
75
-
76
- gr.Markdown(DESCRIPTION)
 
 
 
 
 
77
 
78
  with gr.Tab("Images"):
79
  image_viewer = gr.Gallery(label="Generated images",
 
48
  #print(video_files)
49
 
50
 
51
+ DESCRIPTION = """# PROJET MOULIN SIMON """
52
 
53
  css = '''
54
  .gradio-container {max-width: 1280px !important; height:90%;}
 
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
 
 
78
  # js_str = f.read()
79
  #demo.load(_js=js_str)
80
 
81
+
82
+ # gr.Markdown(DESCRIPTION)
83
+ # gr.Image(BASE_DIR + 'assets/images/banner-dugrainaupain.jpg', type='filepath')
84
+ gr.HTML('''<img src="assets/images/banner-dugrainaupain.jpg">''')
85
+
86
+ with gr.Tab("LE PROJET....."):
87
+ gr.HTML(read_text_file("assets/html/intro.txt"))
88
 
89
  with gr.Tab("Images"):
90
  image_viewer = gr.Gallery(label="Generated images",
assets/images/banner-dugrainaupain.jpg ADDED
infos.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ https://huggingface.co/spaces/menorki/projet-moulin-belle-ile
2
+ https://menorki-projet-moulin-belle-ile.hf.space/
script.js ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function demo_load(x) {
2
+ document.body.scrollTop = document.documentElement.scrollTop = 0;
3
+
4
+ function gradioApp() {
5
+ const elems = document.getElementsByTagName('gradio-app');
6
+ const elem = elems.length == 0 ? document : elems[0];
7
+
8
+ if (elem !== document) {
9
+ elem.getElementById = function(id) {
10
+ return document.getElementById(id);
11
+ };
12
+ }
13
+ return elem.shadowRoot ? elem.shadowRoot : elem;
14
+ }
15
+
16
+ function all_gallery_buttons() {
17
+ var allGalleryButtons = gradioApp().querySelectorAll('#outputgallery .thumbnail-item.thumbnail-small');
18
+ var visibleGalleryButtons = [];
19
+ allGalleryButtons.forEach(function(elem) {
20
+ if (elem.parentElement.offsetParent) {
21
+ visibleGalleryButtons.push(elem);
22
+ }
23
+ });
24
+ return visibleGalleryButtons;
25
+ }
26
+
27
+ function selected_gallery_button() {
28
+ return all_gallery_buttons().find(elem => elem.classList.contains('selected')) ?? null;
29
+ }
30
+
31
+ function selected_gallery_index() {
32
+ return all_gallery_buttons().findIndex(elem => elem.classList.contains('selected'));
33
+ }
34
+
35
+ function loadImg(src){
36
+ return new Promise((resolve, reject) => {
37
+ let img = new Image()
38
+ img.onload = () => resolve(img)
39
+ img.onerror = reject
40
+ img.src = src
41
+ })
42
+ }
43
+
44
+ async function resize_b64_img(b64_img, max_side=2048) {
45
+ var img = await loadImg(b64_img);
46
+ naturalWidth = img.naturalWidth;
47
+ naturalHeight = img.naturalHeight;
48
+
49
+ if (naturalWidth > max_side || naturalHeight > max_side) {
50
+ var width = 0;
51
+ var height = 0;
52
+ if (naturalWidth >= naturalHeight) {
53
+ width = max_side;
54
+ height = Math.ceil((max_side / naturalWidth) * naturalHeight);
55
+ } else {
56
+ height = max_side;
57
+ width = Math.ceil((max_side / naturalHeight) * naturalWidth);
58
+ }
59
+
60
+ var canvas = document.createElement('canvas');
61
+ ctx = canvas.getContext('2d');
62
+ canvas.width = width;
63
+ canvas.height = height;
64
+ ctx.drawImage(img, 0, 0, width, height);
65
+ return canvas.toDataURL();
66
+ }
67
+ return b64_img;
68
+ }
69
+
70
+ // fix image preview on mobile
71
+ function imageMaskResize() {
72
+ const canvases = gradioApp().querySelectorAll('#inputmask canvas');
73
+ if (!canvases.length) {
74
+ window.removeEventListener('resize', imageMaskResize);
75
+ return;
76
+ }
77
+
78
+ const wrapper = canvases[0].closest('.wrap');
79
+ const previewImage = wrapper.previousElementSibling;
80
+
81
+ if (!previewImage.complete) {
82
+ previewImage.addEventListener('load', imageMaskResize);
83
+ return;
84
+ }
85
+
86
+ const w = previewImage.width;
87
+ const h = previewImage.height;
88
+ const nw = previewImage.naturalWidth;
89
+ const nh = previewImage.naturalHeight;
90
+ const portrait = nh > nw;
91
+
92
+ const wW = Math.min(w, portrait ? h / nh * nw : w / nw * nw);
93
+ const wH = Math.min(h, portrait ? h / nh * nh : w / nw * nh);
94
+
95
+ wrapper.style.width = `${wW}px`;
96
+ wrapper.style.height = `${wH}px`;
97
+ wrapper.style.left = `0px`;
98
+ wrapper.style.top = `0px`;
99
+
100
+ canvases.forEach(c => {
101
+ c.style.width = c.style.height = '';
102
+ c.style.maxWidth = '100%';
103
+ c.style.maxHeight = '100%';
104
+ c.style.objectFit = 'contain';
105
+ });
106
+ }
107
+
108
+ window.gradioApp = gradioApp
109
+ window.all_gallery_buttons = all_gallery_buttons
110
+ window.selected_gallery_button = selected_gallery_button
111
+ window.selected_gallery_index = selected_gallery_index
112
+ window.resize_b64_img = resize_b64_img
113
+ window.imageMaskResize = imageMaskResize;
114
+
115
+ window.addEventListener('resize', imageMaskResize);
116
+ }