ZacLiu commited on
Commit
30c73de
·
1 Parent(s): 9e51e77

add rest files

Browse files
Files changed (7) hide show
  1. .DS_Store +0 -0
  2. css_and_js.py +92 -0
  3. footer.html +18 -0
  4. header.html +43 -0
  5. js/index.js +186 -0
  6. share_btn.py +60 -0
  7. style.css +81 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
css_and_js.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from os import path
2
+ import json
3
+
4
+
5
+ def readTextFile(*args):
6
+ dir = path.dirname(__file__)
7
+ entry = path.join(dir, *args)
8
+ with open(entry, "r", encoding="utf8") as f:
9
+ data = f.read()
10
+ return data
11
+
12
+
13
+ def css(opt):
14
+ styling = readTextFile("css", "styles.css")
15
+ # TODO: @altryne restore this before merge
16
+ if not opt.no_progressbar_hiding:
17
+ styling += readTextFile("css", "no_progress_bar.css")
18
+ return styling
19
+
20
+
21
+ def js(opt):
22
+ data = readTextFile("js", "index.js")
23
+ data = "(z) => {" + data + "; return z ?? [] }"
24
+ return data
25
+
26
+
27
+ # TODO : @altryne fix this to the new JS format
28
+ js_copy_txt2img_output = "(x) => {navigator.clipboard.writeText(document.querySelector('gradio-app').shadowRoot.querySelector('#highlight .textfield').textContent.replace(/\s+/g,' ').replace(/: /g,':'))}"
29
+
30
+
31
+
32
+ js_parse_prompt ="""
33
+ (txt2img_prompt, txt2img_width, txt2img_height, txt2img_steps, txt2img_seed, txt2img_batch_count, txt2img_cfg) => {
34
+
35
+ const prompt_input = document.querySelector('gradio-app').shadowRoot.querySelector('#prompt_input [data-testid="textbox"]');
36
+ const multiline = document.querySelector('gradio-app').shadowRoot.querySelector('#submit_on_enter label:nth-child(2)')
37
+ if (prompt_input.scrollWidth > prompt_input.clientWidth + 10 ) {
38
+ multiline.click();
39
+ }
40
+
41
+
42
+ let height_match = /(?:-h|-H|--height|height)[ :]?(?<height>\d+) /.exec(txt2img_prompt);
43
+ if (height_match) {
44
+ txt2img_height = Math.round(height_match.groups.height / 64) * 64;
45
+ txt2img_prompt = txt2img_prompt.replace(height_match[0], '');
46
+ }
47
+ let width_match = /(?:-w|-W|--width|width)[ :]?(?<width>\d+) /.exec(txt2img_prompt);
48
+ if (width_match) {
49
+ txt2img_width = Math.round(width_match.groups.width / 64) * 64;
50
+ txt2img_prompt = txt2img_prompt.replace(width_match[0], '');
51
+ }
52
+ let steps_match = /(?:-s|--steps|steps)[ :]?(?<steps>\d+) /.exec(txt2img_prompt);
53
+ if (steps_match) {
54
+ txt2img_steps = steps_match.groups.steps.trim();
55
+ txt2img_prompt = txt2img_prompt.replace(steps_match[0], '');
56
+ }
57
+ let seed_match = /(?:-S|--seed|seed)[ :]?(?<seed>\d+) /.exec(txt2img_prompt);
58
+ if (seed_match) {
59
+ txt2img_seed = seed_match.groups.seed;
60
+ txt2img_prompt = txt2img_prompt.replace(seed_match[0], '');
61
+ }
62
+ let batch_count_match = /(?:-n|-N|--number|number)[ :]?(?<batch_count>\d+) /.exec(txt2img_prompt);
63
+ if (batch_count_match) {
64
+ txt2img_batch_count = batch_count_match.groups.batch_count;
65
+ txt2img_prompt = txt2img_prompt.replace(batch_count_match[0], '');
66
+ }
67
+ let cfg_scale_match = /(?:-c|-C|--cfg-scale|cfg_scale|cfg)[ :]?(?<cfgscale>\d\.?\d+?) /.exec(txt2img_prompt);
68
+ if (cfg_scale_match) {
69
+ txt2img_cfg = parseFloat(cfg_scale_match.groups.cfgscale).toFixed(1);
70
+ txt2img_prompt = txt2img_prompt.replace(cfg_scale_match[0], '');
71
+ }
72
+ let sampler_match = /(?:-A|--sampler|sampler)[ :]?(?<sampler>\w+) /.exec(txt2img_prompt);
73
+ if (sampler_match) {
74
+
75
+ txt2img_prompt = txt2img_prompt.replace(sampler_match[0], '');
76
+ }
77
+
78
+ return [txt2img_prompt, parseInt(txt2img_width), parseInt(txt2img_height), parseInt(txt2img_steps), txt2img_seed, parseInt(txt2img_batch_count), parseFloat(txt2img_cfg)];
79
+ }
80
+ """
81
+
82
+
83
+ # Wrap the typical SD method call into async closure for ease of use
84
+ # Supplies the js function with a params object
85
+ # That includes all the passed arguments and input from Gradio: x
86
+ # ATTENTION: x is an array of values of all components passed to your
87
+ # python event handler
88
+ # Example call in Gradio component's event handler (pass the result to _js arg):
89
+ # _js=call_JS("myJsMethod", arg1="string", arg2=100, arg3=[])
90
+ def call_JS(sd_method, **kwargs):
91
+ param_str = json.dumps(kwargs)
92
+ return f"async (...x) => {{ return await SD.{sd_method}({{ x, ...{param_str} }}) ?? []; }}"
footer.html ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="footer">
2
+ <p> - Model by <a href="https://github.com/FlagAI-Open/FlagAI"><img src="https://github-link-card.s3.ap-northeast-1.amazonaws.com/FlagAI-Open/FlagAI.png" width="1200px"></a > - Gradio Demo by 🤗 Hugging Face
3
+ </p>
4
+ <!-- <p><a href="https://github.com/FlagAI-Open/FlagAI"><img src="https://raw.githubusercontent.com/920232796/test/master/contributors.png" width="1200px"></a >
5
+ </p> -->
6
+
7
+ <div class="acknowledgments">
8
+ <p><h4 style="font-weight: bold; font-size: 20px; margin-top: 20px;">LICENSE</h4>
9
+ The model is licensed with a <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" style="text-decoration: underline;" target="_blank">CreativeML Open RAIL-M</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a>
10
+ </p>
11
+
12
+ <p><h4 style="font-weight: bold; font-size: 20px;">Contributing</h4>
13
+ Thanks for your interest in contributing! There are many ways to get involved; start with our <a href="https://github.com/FlagAI-Open/FlagAI" style="text-decoration: underline;" target="_blank">contributor guidelines</a> and then check these <a href="https://github.com/FlagAI-Open/FlagAI" style="text-decoration: underline;" target="_blank"> open issues</a> for specific tasks.
14
+ </p>
15
+ </div>
16
+ </div>
17
+
18
+
header.html ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
2
+ <div
3
+ style="
4
+ display: inline-flex;
5
+ gap: 0.8rem;
6
+ font-size: 1.75rem;
7
+ margin-bottom: 10px;
8
+ width: 600px;
9
+ height: 200px;
10
+ margin: 0 auto;
11
+ /* border: 1px solid red; */
12
+ justify-content: center;
13
+ "
14
+
15
+ <a href="https://github.com/FlagAI-Open/FlagAI"><img src="https://raw.githubusercontent.com/920232796/test/master/WechatIMG6906.png" alt="FlagAI" width="80%" height="80%" style="margin: 0 auto;"></a>
16
+ </div>
17
+ <div
18
+ style="
19
+ display: inline-flex;
20
+ align-items: center;
21
+ gap: 0.8rem;
22
+ font-size: 1.75rem;
23
+ margin-bottom: 10px;
24
+ justify-content: center;
25
+ ">
26
+ <a href="https://github.com/FlagAI-Open/FlagAI"><h1 style="font-weight: 900; margin-bottom: 7px;">
27
+ FlagStudio
28
+ </h1></a>
29
+ </div>
30
+ <p style="margin-bottom: 10px; font-size: 94%">
31
+ FlagStudio 项目致力于贡献优秀AI生成艺术作品。此双语文生图模型项目基于 <a href="https://huggingface.co/CompVis/stable-diffusion" style="text-decoration: underline;">stable diffusion</a>,由BAAI旗下的FlagAI团队提供支持,相关代码和模型权重在<a href="https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltDiffusion" style="text-decoration: underline;">AltDiffusion</a>中进行开源。
32
+ </p>
33
+ <p style="margin-bottom: 10px; font-size: 94%">
34
+ FlagStudio aims to provide high quality AI-generated artwork. Our current bilingual model is based on the original <a href="https://huggingface.co/CompVis/stable-diffusion" style="text-decoration: underline;">stable diffusion</a> model and is capable to generate images from both Chinese and English text. FlagStudio is developed and supported by the FlagAI team. Relevant code and model weights released in <a href="https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltDiffusion" style="text-decoration: underline;">AltDiffusion</a>.(open.platform@baai.ac.cn)
35
+ </p>
36
+ <p style="margin-bottom: 10px; font-size: 94%">
37
+ AltDiffusion has been added to 🧨Diffusers, see the documentation page: <a href="https://huggingface.co/docs/diffusers/main/en/api/pipelines/alt_diffusion">🧨 Pipeline doc</a>
38
+ </p>
39
+ <p style="margin-bottom: 10px; font-size: 94%; text-align: left;">
40
+ 我们在colab设置了一个脚本,你可以在colab试用我们的模型!(We have a script on colab, You can try our models on colab.Enjoy it!)
41
+ <a href="https://colab.research.google.com/drive/1htPovT5YNutl2i31mIYrOzlIgGLm06IX#scrollTo=0KXFRkjG1RVk"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>
42
+ </p>
43
+ </div>
js/index.js ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ window.SD = (() => {
2
+ /*
3
+ * Painterro is made a field of the SD global object
4
+ * To provide convinience when using w() method in css_and_js.py
5
+ */
6
+ class PainterroClass {
7
+ static isOpen = false;
8
+ static async init ({ x, toId }) {
9
+ console.log(x)
10
+
11
+ const originalImage = x[2] === 'Mask' ? x[1]?.image : x[0];
12
+
13
+ if (window.Painterro === undefined) {
14
+ try {
15
+ await this.load();
16
+ } catch (e) {
17
+ SDClass.error(e);
18
+
19
+ return this.fallback(originalImage);
20
+ }
21
+ }
22
+
23
+ if (this.isOpen) {
24
+ return this.fallback(originalImage);
25
+ }
26
+ this.isOpen = true;
27
+
28
+ let resolveResult;
29
+ const paintClient = Painterro({
30
+ hiddenTools: ['arrow'],
31
+ onHide: () => {
32
+ resolveResult?.(null);
33
+ },
34
+ saveHandler: (image, done) => {
35
+ const data = image.asDataURL();
36
+
37
+ // ensures stable performance even
38
+ // when the editor is in interactive mode
39
+ SD.clearImageInput(SD.el.get(`#${toId}`));
40
+
41
+ resolveResult(data);
42
+
43
+ done(true);
44
+ paintClient.hide();
45
+ },
46
+ });
47
+
48
+ const result = await new Promise((resolve) => {
49
+ resolveResult = resolve;
50
+ paintClient.show(originalImage);
51
+ });
52
+ this.isOpen = false;
53
+
54
+ return result ? this.success(result) : this.fallback(originalImage);
55
+ }
56
+ static success (result) { return [result, { image: result, mask: result }] };
57
+ static fallback (image) { return [image, { image: image, mask: image }] };
58
+ static load () {
59
+ return new Promise((resolve, reject) => {
60
+ const scriptId = '__painterro-script';
61
+ if (document.getElementById(scriptId)) {
62
+ reject(new Error('Tried to load painterro script, but script tag already exists.'));
63
+ return;
64
+ }
65
+
66
+ const styleId = '__painterro-css-override';
67
+ if (!document.getElementById(styleId)) {
68
+ /* Ensure Painterro window is always on top */
69
+ const style = document.createElement('style');
70
+ style.id = styleId;
71
+ style.setAttribute('type', 'text/css');
72
+ style.appendChild(document.createTextNode(`
73
+ .ptro-holder-wrapper {
74
+ z-index: 100;
75
+ }
76
+ `));
77
+ document.head.appendChild(style);
78
+ }
79
+
80
+ const script = document.createElement('script');
81
+ script.id = scriptId;
82
+ script.src = 'https://unpkg.com/painterro@1.2.78/build/painterro.min.js';
83
+ script.onload = () => resolve(true);
84
+ script.onerror = (e) => {
85
+ // remove self on error to enable reattempting load
86
+ document.head.removeChild(script);
87
+ reject(e);
88
+ };
89
+ document.head.appendChild(script);
90
+ });
91
+ }
92
+ }
93
+
94
+ /*
95
+ * Turns out caching elements doesn't actually work in gradio
96
+ * As elements in tabs might get recreated
97
+ */
98
+ class ElementCache {
99
+ #el;
100
+ constructor () {
101
+ this.root = document.querySelector('gradio-app').shadowRoot;
102
+ }
103
+ get (selector) {
104
+ return this.root.querySelector(selector);
105
+ }
106
+ }
107
+
108
+ /*
109
+ * The main helper class to incapsulate functions
110
+ * that change gradio ui functionality
111
+ */
112
+ class SDClass {
113
+ el = new ElementCache();
114
+ Painterro = PainterroClass;
115
+ moveImageFromGallery ({ x, fromId, toId }) {
116
+ x = x[0];
117
+ if (!Array.isArray(x) || x.length === 0) return;
118
+
119
+ this.clearImageInput(this.el.get(`#${toId}`));
120
+
121
+ const i = this.#getGallerySelectedIndex(this.el.get(`#${fromId}`));
122
+
123
+ return [x[i].replace('data:;','data:image/png;')];
124
+ }
125
+ async copyImageFromGalleryToClipboard ({ x, fromId }) {
126
+ x = x[0];
127
+ if (!Array.isArray(x) || x.length === 0) return;
128
+
129
+ const i = this.#getGallerySelectedIndex(this.el.get(`#${fromId}`));
130
+
131
+ const data = x[i];
132
+ const blob = await (await fetch(data.replace('data:;','data:image/png;'))).blob();
133
+ const item = new ClipboardItem({'image/png': blob});
134
+
135
+ await this.copyToClipboard([item]);
136
+ }
137
+ clickFirstVisibleButton({ rowId }) {
138
+ const generateButtons = this.el.get(`#${rowId}`).querySelectorAll('.gr-button-primary');
139
+
140
+ if (!generateButtons) return;
141
+
142
+ for (let i = 0, arr = [...generateButtons]; i < arr.length; i++) {
143
+ const cs = window.getComputedStyle(arr[i]);
144
+
145
+ if (cs.display !== 'none' && cs.visibility !== 'hidden') {
146
+ console.log(arr[i]);
147
+
148
+ arr[i].click();
149
+ break;
150
+ }
151
+ }
152
+ }
153
+ async gradioInputToClipboard ({ x }) { return this.copyToClipboard(x[0]); }
154
+ async copyToClipboard (value) {
155
+ if (!value || typeof value === 'boolean') return;
156
+ try {
157
+ if (Array.isArray(value) &&
158
+ value.length &&
159
+ value[0] instanceof ClipboardItem) {
160
+ await navigator.clipboard.write(value);
161
+ } else {
162
+ await navigator.clipboard.writeText(value);
163
+ }
164
+ } catch (e) {
165
+ SDClass.error(e);
166
+ }
167
+ }
168
+ static error (e) {
169
+ console.error(e);
170
+ if (typeof e === 'string') {
171
+ alert(e);
172
+ } else if(typeof e === 'object' && Object.hasOwn(e, 'message')) {
173
+ alert(e.message);
174
+ }
175
+ }
176
+ clearImageInput (imageEditor) {
177
+ imageEditor?.querySelector('.modify-upload button:last-child')?.click();
178
+ }
179
+ #getGallerySelectedIndex (gallery) {
180
+ const selected = gallery.querySelector(`.\\!ring-2`);
181
+ return selected ? [...selected.parentNode.children].indexOf(selected) : 0;
182
+ }
183
+ }
184
+
185
+ return new SDClass();
186
+ })();
share_btn.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ community_icon_html = """<svg id="share-btn-share-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32">
2
+ <path d="M20.6081 3C21.7684 3 22.8053 3.49196 23.5284 4.38415C23.9756 4.93678 24.4428 5.82749 24.4808 7.16133C24.9674 7.01707 25.4353 6.93643 25.8725 6.93643C26.9833 6.93643 27.9865 7.37587 28.696 8.17411C29.6075 9.19872 30.0124 10.4579 29.8361 11.7177C29.7523 12.3177 29.5581 12.8555 29.2678 13.3534C29.8798 13.8646 30.3306 14.5763 30.5485 15.4322C30.719 16.1032 30.8939 17.5006 29.9808 18.9403C30.0389 19.0342 30.0934 19.1319 30.1442 19.2318C30.6932 20.3074 30.7283 21.5229 30.2439 22.6548C29.5093 24.3704 27.6841 25.7219 24.1397 27.1727C21.9347 28.0753 19.9174 28.6523 19.8994 28.6575C16.9842 29.4379 14.3477 29.8345 12.0653 29.8345C7.87017 29.8345 4.8668 28.508 3.13831 25.8921C0.356375 21.6797 0.754104 17.8269 4.35369 14.1131C6.34591 12.058 7.67023 9.02782 7.94613 8.36275C8.50224 6.39343 9.97271 4.20438 12.4172 4.20438H12.4179C12.6236 4.20438 12.8314 4.2214 13.0364 4.25468C14.107 4.42854 15.0428 5.06476 15.7115 6.02205C16.4331 5.09583 17.134 4.359 17.7682 3.94323C18.7242 3.31737 19.6794 3 20.6081 3ZM20.6081 5.95917C20.2427 5.95917 19.7963 6.1197 19.3039 6.44225C17.7754 7.44319 14.8258 12.6772 13.7458 14.7131C13.3839 15.3952 12.7655 15.6837 12.2086 15.6837C11.1036 15.6837 10.2408 14.5497 12.1076 13.1085C14.9146 10.9402 13.9299 7.39584 12.5898 7.1776C12.5311 7.16799 12.4731 7.16355 12.4172 7.16355C11.1989 7.16355 10.6615 9.33114 10.6615 9.33114C10.6615 9.33114 9.0863 13.4148 6.38031 16.206C3.67434 18.998 3.5346 21.2388 5.50675 24.2246C6.85185 26.2606 9.42666 26.8753 12.0653 26.8753C14.8021 26.8753 17.6077 26.2139 19.1799 25.793C19.2574 25.7723 28.8193 22.984 27.6081 20.6107C27.4046 20.212 27.0693 20.0522 26.6471 20.0522C24.9416 20.0522 21.8393 22.6726 20.5057 22.6726C20.2076 22.6726 19.9976 22.5416 19.9116 22.222C19.3433 20.1173 28.552 19.2325 27.7758 16.1839C27.639 15.6445 27.2677 15.4256 26.746 15.4263C24.4923 15.4263 19.4358 19.5181 18.3759 19.5181C18.2949 19.5181 18.2368 19.4937 18.2053 19.4419C17.6743 18.557 17.9653 17.9394 21.7082 15.6009C25.4511 13.2617 28.0783 11.8545 26.5841 10.1752C26.4121 9.98141 26.1684 9.8956 25.8725 9.8956C23.6001 9.89634 18.2311 14.9403 18.2311 14.9403C18.2311 14.9403 16.7821 16.496 15.9057 16.496C15.7043 16.496 15.533 16.4139 15.4169 16.2112C14.7956 15.1296 21.1879 10.1286 21.5484 8.06535C21.7928 6.66715 21.3771 5.95917 20.6081 5.95917Z" fill="#FF9D00"></path>
3
+ <path d="M5.50686 24.2246C3.53472 21.2387 3.67446 18.9979 6.38043 16.206C9.08641 13.4147 10.6615 9.33111 10.6615 9.33111C10.6615 9.33111 11.2499 6.95933 12.59 7.17757C13.93 7.39581 14.9139 10.9401 12.1069 13.1084C9.29997 15.276 12.6659 16.7489 13.7459 14.713C14.8258 12.6772 17.7747 7.44316 19.304 6.44221C20.8326 5.44128 21.9089 6.00204 21.5484 8.06532C21.188 10.1286 14.795 15.1295 15.4171 16.2118C16.0391 17.2934 18.2312 14.9402 18.2312 14.9402C18.2312 14.9402 25.0907 8.49588 26.5842 10.1752C28.0776 11.8545 25.4512 13.2616 21.7082 15.6008C17.9646 17.9393 17.6744 18.557 18.2054 19.4418C18.7372 20.3266 26.9998 13.1351 27.7759 16.1838C28.5513 19.2324 19.3434 20.1173 19.9117 22.2219C20.48 24.3274 26.3979 18.2382 27.6082 20.6107C28.8193 22.9839 19.2574 25.7722 19.18 25.7929C16.0914 26.62 8.24723 28.3726 5.50686 24.2246Z" fill="#FFD21E"></path>
4
+ </svg>"""
5
+
6
+ loading_icon_html = """<svg id="share-btn-loading-icon" style="display:none;" class="animate-spin"
7
+ style="color: #ffffff;
8
+ "
9
+ xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" fill="none" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>"""
10
+
11
+ share_js = """async () => {
12
+ async function uploadFile(file){
13
+ const UPLOAD_URL = 'https://huggingface.co/uploads';
14
+ const response = await fetch(UPLOAD_URL, {
15
+ method: 'POST',
16
+ headers: {
17
+ 'Content-Type': file.type,
18
+ 'X-Requested-With': 'XMLHttpRequest',
19
+ },
20
+ body: file, /// <- File inherits from Blob
21
+ });
22
+ const url = await response.text();
23
+ return url;
24
+ }
25
+ const gradioEl = document.querySelector('body > gradio-app');
26
+ const imgEls = gradioEl.querySelectorAll('#gallery img');
27
+ const promptTxt = gradioEl.querySelector('#prompt-text-input input').value;
28
+ const shareBtnEl = gradioEl.querySelector('#share-btn');
29
+ const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
30
+ const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
31
+ if(!imgEls.length){
32
+ return;
33
+ };
34
+ shareBtnEl.style.pointerEvents = 'none';
35
+ shareIconEl.style.display = 'none';
36
+ loadingIconEl.style.removeProperty('display');
37
+ const files = await Promise.all(
38
+ [...imgEls].map(async (imgEl) => {
39
+ const res = await fetch(imgEl.src);
40
+ const blob = await res.blob();
41
+ const imgId = Date.now() % 200;
42
+ const fileName = `diffuse-the-rest-${{imgId}}.png`;
43
+ return new File([blob], fileName, { type: 'image/png' });
44
+ })
45
+ );
46
+ const urls = await Promise.all(files.map((f) => uploadFile(f)));
47
+ const htmlImgs = urls.map(url => `<img src='${url}' width='400' height='400'>`);
48
+ const descriptionMd = `<div style='display: flex; flex-wrap: wrap; column-gap: 0.75rem;'>
49
+ ${htmlImgs.join(`\n`)}
50
+ </div>`;
51
+ const params = new URLSearchParams({
52
+ title: promptTxt,
53
+ description: descriptionMd,
54
+ });
55
+ const paramsStr = params.toString();
56
+ window.open(`https://huggingface.co/spaces/BAAI/bilingual_stable_diffusion/discussions/new?${paramsStr}`, '_blank');
57
+ shareBtnEl.style.removeProperty('pointer-events');
58
+ shareIconEl.style.removeProperty('display');
59
+ loadingIconEl.style.display = 'none';
60
+ }"""
style.css ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .gradio-container {
2
+ font-family: 'IBM Plex Sans', sans-serif;
3
+ }
4
+ .gr-button {
5
+ color: white;
6
+ /* border-color: black; */
7
+ /* background: black; */
8
+ background: rgb(60, 145, 238);
9
+ }
10
+ /* input[type='range'] {
11
+ accent-color: rgb(60, 145, 238);
12
+ }
13
+ .dark input[type='range'] {
14
+ accent-color: #dfdfdf;
15
+ } */
16
+ .container {
17
+ max-width: 900px;
18
+ margin: auto;
19
+ padding-top: 1.5rem;
20
+ }
21
+ #gallery {
22
+ min-height: 22rem;
23
+ margin-bottom: 15px;
24
+ margin-left: auto;
25
+ margin-right: auto;
26
+ border-bottom-right-radius: .5rem !important;
27
+ border-bottom-left-radius: .5rem !important;
28
+ }
29
+ #gallery>div>.h-full {
30
+ min-height: 20rem;
31
+ }
32
+ .details:hover {
33
+ text-decoration: underline;
34
+ }
35
+ .gr-button {
36
+ white-space: nowrap;
37
+ }
38
+ /* .gr-button:focus {
39
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
40
+ outline: none;
41
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
42
+ --tw-border-opacity: 1;
43
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
44
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
45
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
46
+ --tw-ring-opacity: .5;
47
+ } */
48
+ .footer {
49
+ margin-bottom: 45px;
50
+ margin-top: 20px;
51
+ /* text-align: center; */
52
+ border-bottom: 1px solid #e5e5e5;
53
+ }
54
+ .footer>p {
55
+ font-size: .8rem;
56
+ display: inline-block;
57
+ padding: 0 10px;
58
+ transform: translateY(10px);
59
+ background: white;
60
+ }
61
+ .footer>p>h4 {
62
+ font-size: .20rem;
63
+ display: inline-block;
64
+ padding: 0 10px;
65
+ transform: translateY(10px);
66
+ background: white;
67
+ font-weight: bold;
68
+ }
69
+ .dark .footer {
70
+ /* border-color: #303030; */
71
+ border-color: rgb(60, 145, 238);
72
+ }
73
+ .dark .footer>p {
74
+ /* background: #0b0f19; */
75
+ background: rgb(60, 145, 238);
76
+ }
77
+ .prompt h4{
78
+ margin: 1.25em 0 .25em 0;
79
+ font-weight: bold;
80
+ font-size: 115%;
81
+ }