ikmalsaid commited on
Commit
57f780e
β€’
1 Parent(s): 966a827

added/updated app files

Browse files
README.md CHANGED
@@ -5,7 +5,7 @@ colorFrom: red
5
  colorTo: purple
6
  sdk: gradio
7
  sdk_version: 4.20.1
8
- app_file: app.py
9
  pinned: false
10
  license: agpl-3.0
11
  ---
 
5
  colorTo: purple
6
  sdk: gradio
7
  sdk_version: 4.20.1
8
+ app_file: app_upscale.py
9
  pinned: false
10
  license: agpl-3.0
11
  ---
app.py β†’ app_upscale.py RENAMED
@@ -1,4 +1,4 @@
1
- import gradio as ui; from modules.engine_upscale import *
2
  feature = 'Image Upscaler'
3
  '''
4
  _____________________________________________________________________
@@ -11,11 +11,11 @@ _____________________________________________________________________
11
  _____________________________________________________________________
12
 
13
  '''
14
- with ui.Blocks(css=css, title=title(feature), theme=theme, analytics_enabled=False) as stella:
15
 
16
  with ui.Group():
17
  input_upscale = ui.Image(type='pil', label=title(feature), sources=['upload'], height="40vh")
18
- output_upscale = ui.Gallery(type='pil', object_fit="cover", height="43.4vh", show_share_button=False, columns=1, rows=1, show_label=False, preview=True)
19
 
20
  with ui.Row():
21
  ui.ClearButton(value="Reset", components=[input_upscale, output_upscale])
@@ -24,4 +24,4 @@ with ui.Blocks(css=css, title=title(feature), theme=theme, analytics_enabled=Fal
24
  process_upscale = submit_upscale.click(fn=upscale, inputs=[input_upscale], outputs=[output_upscale])
25
 
26
  if __name__ == "__main__":
27
- stella.queue(default_concurrency_limit=100, api_open=True).launch(inbrowser=True, favicon_path="favicon.ico")
 
1
+ from modules.engine_upscale import *
2
  feature = 'Image Upscaler'
3
  '''
4
  _____________________________________________________________________
 
11
  _____________________________________________________________________
12
 
13
  '''
14
+ with ui.Blocks(css=css, title=title(feature), theme=theme, analytics_enabled=False, head=jsx) as stella:
15
 
16
  with ui.Group():
17
  input_upscale = ui.Image(type='pil', label=title(feature), sources=['upload'], height="40vh")
18
+ output_upscale = ui.Gallery(type='pil', object_fit="cover", height="50vh", show_share_button=False, columns=1, rows=1, show_label=False, preview=True)
19
 
20
  with ui.Row():
21
  ui.ClearButton(value="Reset", components=[input_upscale, output_upscale])
 
24
  process_upscale = submit_upscale.click(fn=upscale, inputs=[input_upscale], outputs=[output_upscale])
25
 
26
  if __name__ == "__main__":
27
+ stella.queue(default_concurrency_limit=100).launch(inbrowser=True, favicon_path="favicon.ico")
modules/engine_upscale.py CHANGED
@@ -1,17 +1,9 @@
1
- import gradio as ui; import requests; from requests.exceptions import Timeout
2
  from io import BytesIO; from PIL import Image
3
 
4
- ###################################################################################################################
5
- # Import from modules
6
- ###################################################################################################################
7
-
8
  from modules.service_endpoints import *
9
  from modules.service_configs import *
10
 
11
- ###################################################################################################################
12
- # Image upscale process
13
- ###################################################################################################################
14
-
15
  def upscale(upscale_input, progress=ui.Progress()):
16
  image_bytes = BytesIO()
17
  upscale_input.save(image_bytes, format='JPEG')
@@ -20,8 +12,8 @@ def upscale(upscale_input, progress=ui.Progress()):
20
  payload = {'model_version': (None, '1')}; data = [('image',('upscale_input.jpg', image_bytes.getvalue(), 'image/jpeg'))]
21
 
22
  try:
23
- progress(0.99, desc="Upscaling image...")
24
- response = requests.post(mode['upscale'], headers=head, data=payload, files=data, timeout=30)
25
 
26
  if len(response.content) < 65 * 1024:
27
  print(reject())
 
1
+ import requests; from requests.exceptions import Timeout
2
  from io import BytesIO; from PIL import Image
3
 
 
 
 
 
4
  from modules.service_endpoints import *
5
  from modules.service_configs import *
6
 
 
 
 
 
7
  def upscale(upscale_input, progress=ui.Progress()):
8
  image_bytes = BytesIO()
9
  upscale_input.save(image_bytes, format='JPEG')
 
12
  payload = {'model_version': (None, '1')}; data = [('image',('upscale_input.jpg', image_bytes.getvalue(), 'image/jpeg'))]
13
 
14
  try:
15
+ progress(0.95, desc="Upscaling image...")
16
+ response = requests.post(mode['upscale'], headers=head, data=payload, files=data, timeout=(60, 60))
17
 
18
  if len(response.content) < 65 * 1024:
19
  print(reject())
modules/service_configs.py CHANGED
@@ -1,53 +1,23 @@
1
- import gradio as ui; from datetime import datetime; import logging
 
2
 
3
  # enable debug
4
  logging.basicConfig(level=logging.DEBUG)
5
 
6
  # global theme
7
  theme = ui.themes.Default(
8
- font=[ui.themes.GoogleFont('Roboto Condensed'), 'Arial'],
9
- text_size=ui.themes.Size(lg="16px", md="16px", sm="16px", xl="16px", xs="16px", xxl="16px", xxs="16px"),
10
  primary_hue='rose', secondary_hue='rose', neutral_hue='zinc', radius_size=ui.themes.sizes.radius_none)
11
 
12
- css = '''
13
- footer {
14
- display: none !important;
15
- }
16
-
17
- div.svelte-vt1mxs>*, div.svelte-vt1mxs>.form > * {
18
- border: none;
19
- }
20
-
21
- .app.svelte-182fdeq.svelte-182fdeq {
22
- padding: 0px !important;
23
- }
24
-
25
- .grid-wrap.svelte-hpz95u.svelte-hpz95u {
26
- overflow-y: auto !important;
27
- }
28
-
29
- .selected.svelte-1uw5tnk {
30
- background: #262629 !important;
31
- }
32
-
33
- .closed.svelte-g7pfx4>button.svelte-g7pfx4 {
34
- display: none !important;
35
- }
36
-
37
- gradio-app {
38
- background: none !important;
39
- }
40
-
41
- input.svelte-1f354aw.svelte-1f354aw, textarea.svelte-1f354aw.svelte-1f354aw {
42
- text-align: justify !important;
43
- }
44
- '''
45
-
46
  # global locale - english
47
  success = 'That worked successfully!'
48
  single_error = 'That did not work!'
49
  quads_error = 'Some images cannot be processed!'
50
  empty_error = 'Prompt field cannot be empty!'
 
 
 
51
  received = 'Request Received'
52
  timed = 'Request Timeout'
53
  rejected = 'Request Error/Rejected'
@@ -60,12 +30,14 @@ spholder2 = 'Things to get rid of!'
60
  spholder3 = 'Put wonders into the generated prompt!'
61
  sprompt = 'Generate images of:'
62
  sprompt1 = 'Based on image, create:'
 
63
  smodel = 'Using the AI model:'
64
  smode = 'Using the mode:'
65
  sratio = 'In the size of:'
66
  sstyle = 'Inspired by the style of:'
67
  squality = 'At a quality level of:'
68
  snumber = 'With a quantity of:'
 
69
 
70
  # global function
71
  def timestamp(): return f"[{datetime.now().strftime('%d/%m/%y at %H:%M:%S')}]"
@@ -75,4 +47,235 @@ def reject(): return f"{timestamp()} \U0000274C {rejected}"
75
  def done(): return f"{timestamp()} \U0001F618 {complete}"
76
  def header(feature): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 5px">{feature}</h4></center>')
77
  def footer(): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 0px">{liability}<br></h4>{rights}</center>')
78
- def title(feature): return f"{feature}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as ui; from datetime import datetime; import logging, requests, json, random
2
+ from modules.service_endpoints import *; import numpy as np
3
 
4
  # enable debug
5
  logging.basicConfig(level=logging.DEBUG)
6
 
7
  # global theme
8
  theme = ui.themes.Default(
9
+ font=[ui.themes.GoogleFont('IBM Plex Sans Condensed')], font_mono=[ui.themes.GoogleFont('IBM Plex Sans Condensed')],
10
+ text_size=ui.themes.Size(lg="18px", md="18px", sm="18px", xl="18px", xs="18px", xxl="18px", xxs="18px"),
11
  primary_hue='rose', secondary_hue='rose', neutral_hue='zinc', radius_size=ui.themes.sizes.radius_none)
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # global locale - english
14
  success = 'That worked successfully!'
15
  single_error = 'That did not work!'
16
  quads_error = 'Some images cannot be processed!'
17
  empty_error = 'Prompt field cannot be empty!'
18
+ pf_error = 'Prompt fusion error. Proceeding...'
19
+ pe_error = 'Prompt expansion error. Proceeding...'
20
+ pe_cmd = '(The prompt must intricately describe every part of the image in concrete, objective detail. THINK about what the end goal of the description is, and extrapolate that to what would make satisfying images.)'
21
  received = 'Request Received'
22
  timed = 'Request Timeout'
23
  rejected = 'Request Error/Rejected'
 
30
  spholder3 = 'Put wonders into the generated prompt!'
31
  sprompt = 'Generate images of:'
32
  sprompt1 = 'Based on image, create:'
33
+ sprompt2 = 'Based on image, it shows:'
34
  smodel = 'Using the AI model:'
35
  smode = 'Using the mode:'
36
  sratio = 'In the size of:'
37
  sstyle = 'Inspired by the style of:'
38
  squality = 'At a quality level of:'
39
  snumber = 'With a quantity of:'
40
+ ssmart = 'Using SmartPromptβ„’ mode:'
41
 
42
  # global function
43
  def timestamp(): return f"[{datetime.now().strftime('%d/%m/%y at %H:%M:%S')}]"
 
47
  def done(): return f"{timestamp()} \U0001F618 {complete}"
48
  def header(feature): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 5px">{feature}</h4></center>')
49
  def footer(): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 0px">{liability}<br></h4>{rights}</center>')
50
+ def title(feature): return f"{feature}"
51
+
52
+ # seed generator
53
+ max_seed = np.iinfo(np.int32).max
54
+
55
+ def seeds(a, i: ui.SelectData):
56
+ print(f"Seed mode: {a}")
57
+ if i.value == 'Fixed': return ui.Slider(value=random.randint(0, max_seed), visible=True)
58
+ else: return ui.Slider(visible=False)
59
+
60
+ # prompt fusion to en
61
+ def translate(fusion, progress=ui.Progress()):
62
+ progress(0.05, desc="Initiating fusion")
63
+ try: print(f"{receive()} -> {fusion}"); return requests.get(f"{mode['fusion']}{fusion}", timeout=15).json()[0][0]
64
+ except Exception as e: print(pf_error, e); return fusion
65
+
66
+ # prompt expander
67
+ def expand(expand, progress=ui.Progress()):
68
+ progress(0.10, desc="Initiating expansion")
69
+ # return str(input)
70
+ head = {'Content-Type': 'application/json'}
71
+ body = json.dumps({"sentence": f"{expand} {pe_cmd}", "target_word_count": 30})
72
+ # body = json.dumps({"topic": input, "word_count": 30, "writing_mode": "Simple", "story_genre": "Descriptive"}) # ['story']
73
+ try: print(f"{receive()} -> {expand}"); return requests.post(url=mode['expander'], headers=head, data=body, timeout=15).json()['expanded_sentence']
74
+ except Exception as e: print(pe_error, e); return expand
75
+
76
+ # global head script
77
+ jsx = '''
78
+ <script>
79
+ window.onbeforeunload = function (event) {
80
+ event.returnValue = "Are you sure you want to leave?";
81
+ };
82
+ </script>
83
+ '''
84
+
85
+ # specific css modifiers
86
+ adj = '''
87
+ /* remove layers button */
88
+ .layer-wrap.svelte-g7pfx4.svelte-g7pfx4 {
89
+ display: none !important;
90
+ }
91
+ '''
92
+
93
+ adj2 = '''
94
+ .grid-wrap.svelte-hpz95u.svelte-hpz95u {
95
+ height: 49.8vh;
96
+ }
97
+ '''
98
+
99
+ # global css modifiers
100
+ css = '''
101
+ /* remove scrollbars */
102
+ ::-webkit-scrollbar {
103
+ display: none;
104
+ }
105
+
106
+ ::-webkit-scrollbar-button {
107
+ display: none;
108
+ }
109
+
110
+ body {
111
+ -ms-overflow-style: none;
112
+ }
113
+
114
+ /* remove footer */
115
+ footer {
116
+ display: none !important;
117
+ }
118
+
119
+ /* remove all padding */
120
+ .app.svelte-182fdeq.svelte-182fdeq {
121
+ padding: 0px;
122
+ }
123
+
124
+ /* remove scroll bar in gallery */
125
+ .grid-wrap.svelte-hpz95u.svelte-hpz95u {
126
+ overflow-y: auto;
127
+ }
128
+
129
+ /* remove background */
130
+ gradio-app {
131
+ background: none !important;
132
+ }
133
+
134
+ /* remove borders for tabs*/
135
+ div.svelte-iyf88w {
136
+ border: 0px;
137
+ }
138
+
139
+ /* remove padding for tabs */
140
+ div.svelte-19hvt5v {
141
+ padding: 0px;
142
+ border: 0px;
143
+ }
144
+
145
+ /* remove borders for tab button bottom*/
146
+ .tab-nav.svelte-1uw5tnk {
147
+ border: 0px;
148
+ }
149
+
150
+ /* remove borders for tab button*/
151
+ button.svelte-1uw5tnk {
152
+ border: 0px;
153
+ }
154
+
155
+ /* modify container padding and bg */
156
+ .hide-container.svelte-90oupt {
157
+ padding: var(--block-padding);
158
+ background: var(--block-background-fill);
159
+ }
160
+
161
+ /* set brush to red */
162
+ span.svelte-btgkrd {
163
+ background: rgb(255 0 0 / 60%);
164
+ }
165
+
166
+ /* remove example symbol */
167
+ svg.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno {
168
+ display: none;
169
+ }
170
+
171
+ /* replace selected tab color */
172
+ .selected.svelte-1uw5tnk {
173
+ background: #27272a;
174
+ }
175
+
176
+ /* justify textbox */
177
+ input.svelte-1f354aw.svelte-1f354aw,
178
+ textarea.svelte-1f354aw.svelte-1f354aw {
179
+ text-align: justify;
180
+ }
181
+
182
+ /* modify feature text */
183
+ label.float.svelte-1b6s6s {
184
+ padding-left: 10px;
185
+ padding-top: 6px;
186
+ }
187
+
188
+ /* change feature background */
189
+ label.svelte-1b6s6s {
190
+ background: #27272a;
191
+ }
192
+
193
+ /* remove feature icon */
194
+ span.svelte-1b6s6s {
195
+ display: none;
196
+ }
197
+
198
+ /* remove options line */
199
+ div.svelte-sfqy0y {
200
+ background: none;
201
+ }
202
+
203
+ /* modify layer button */
204
+ .layer-wrap.svelte-g7pfx4.svelte-g7pfx4 {
205
+ background: #27272a;
206
+ }
207
+
208
+ /* modify slider color */
209
+ .dark, .light {
210
+ --slider-color: var(--color-accent);
211
+ }
212
+
213
+ /* chanhe num input padding and height */
214
+ input[type="number"].svelte-pjtc3.svelte-pjtc3 {
215
+ padding: var(--checkbox-label-padding);
216
+ height: 45px;
217
+ }
218
+
219
+ /* disable anti-aliasing on gallery thumb */
220
+ .thumbnail-lg.svelte-hpz95u>img {
221
+ image-rendering: auto;
222
+ }
223
+
224
+ /* disable anti-aliasing on gallery view */
225
+ .image-button.svelte-hpz95u img {
226
+ image-rendering: auto;
227
+ }
228
+
229
+ /* make gallery buttons bigger */
230
+ .icon-buttons.svelte-hpz95u.svelte-hpz95u {
231
+ scale: 2;
232
+ padding-top: 8px;
233
+ padding-right: 15px;
234
+ }
235
+
236
+ /* make img clear btn bigger */
237
+ div.svelte-s6ybro {
238
+ scale: 2;
239
+ padding-right: 5px;
240
+ padding-top: 5px;
241
+ }
242
+
243
+ /* make img dload btn bigger */
244
+ .icon-buttons.svelte-1l6wqyv {
245
+ top: 8px;
246
+ right: 8px;
247
+ scale: 2;
248
+ padding-right: 5px;
249
+ padding-top: 5px;
250
+ }
251
+
252
+ /* remove bg completely */
253
+ body {
254
+ background: none !important;
255
+ }
256
+
257
+ /* wide mode */
258
+ .app.svelte-182fdeq.svelte-182fdeq {
259
+ max-width: 100% !important;
260
+ }
261
+
262
+ /* make prompt consistant */
263
+ label.svelte-1f354aw.svelte-1f354aw {
264
+ padding: 12px;
265
+ }
266
+
267
+ /* remove accord label */
268
+ .label-wrap.open.svelte-s1r2yt {
269
+ display: none;
270
+ }
271
+
272
+ /* make empty gallery taller */
273
+ .unpadded_box.svelte-1oiin9d {
274
+ min-height: 50vh;
275
+ }
276
+
277
+ /* make image contain */
278
+ .image-frame.svelte-rrgd5g img {
279
+ object-fit: contain;
280
+ }
281
+ '''