Vincent Claes commited on
Commit
113288d
1 Parent(s): b597b87

nicer looking gradio app

Browse files
Files changed (4) hide show
  1. app.py +188 -19
  2. poetry.lock +0 -0
  3. pyproject.toml +3 -0
  4. requirements.txt +1 -0
app.py CHANGED
@@ -1,12 +1,8 @@
1
  import os
2
- import io
3
  import requests
4
- import base64
5
 
6
  import gradio as gr
7
- from PIL import Image
8
 
9
- # define the function that will be called when the user inputs text
10
  def get_images(text):
11
  headers = {
12
  "Content-Type": "application/json",
@@ -22,23 +18,196 @@ def get_images(text):
22
  headers=headers,
23
  json={"data": text},
24
  )
25
- # get the list of image data from the response
26
  image_data = response.json()["image"]
27
- # decode the base64-encoded image data and convert it to PIL images
28
- images = [Image.open(io.BytesIO(base64.b64decode(data))) for data in image_data]
29
- # first comes on the top
30
- images.reverse()
31
- # return the list of images
32
  return images
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
 
34
 
35
- # create the gradio app, passing the function as the input and output
36
- app = gr.Interface(
37
- get_images,
38
- gr.components.Textbox(label="Description"),
39
- # gr.components.Image(label="Images", type="pil")
40
- gr.Gallery(label="Images"),
41
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- # start the app
44
- app.launch()
 
1
  import os
 
2
  import requests
 
3
 
4
  import gradio as gr
 
5
 
 
6
  def get_images(text):
7
  headers = {
8
  "Content-Type": "application/json",
 
18
  headers=headers,
19
  json={"data": text},
20
  )
21
+ images = []
22
  image_data = response.json()["image"]
23
+ for image in image_data:
24
+ # got this from https://huggingface.co/spaces/stabilityai/stable-diffusion/blob/main/app.py
25
+ image_b64 = (f"data:image/jpeg;base64,{image}")
26
+ images.append(image_b64)
 
27
  return images
28
+
29
+ css = """
30
+ .gradio-container {
31
+ font-family: 'IBM Plex Sans', sans-serif;
32
+ }
33
+ .gr-button {
34
+ color: white;
35
+ border-color: black;
36
+ background: black;
37
+ }
38
+ input[type='range'] {
39
+ accent-color: black;
40
+ }
41
+ .dark input[type='range'] {
42
+ accent-color: #dfdfdf;
43
+ }
44
+ .container {
45
+ max-width: 730px;
46
+ margin: auto;
47
+ padding-top: 1.5rem;
48
+ }
49
+ #gallery {
50
+ min-height: 22rem;
51
+ margin-bottom: 15px;
52
+ margin-left: auto;
53
+ margin-right: auto;
54
+ border-bottom-right-radius: .5rem !important;
55
+ border-bottom-left-radius: .5rem !important;
56
+ }
57
+ #gallery>div>.h-full {
58
+ min-height: 20rem;
59
+ }
60
+ .details:hover {
61
+ text-decoration: underline;
62
+ }
63
+ .gr-button {
64
+ white-space: nowrap;
65
+ }
66
+ .gr-button:focus {
67
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
68
+ outline: none;
69
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
70
+ --tw-border-opacity: 1;
71
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
72
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
73
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
74
+ --tw-ring-opacity: .5;
75
+ }
76
+ #advanced-btn {
77
+ font-size: .7rem !important;
78
+ line-height: 19px;
79
+ margin-top: 12px;
80
+ margin-bottom: 12px;
81
+ padding: 2px 8px;
82
+ border-radius: 14px !important;
83
+ }
84
+ #advanced-options {
85
+ display: none;
86
+ margin-bottom: 20px;
87
+ }
88
+ .footer {
89
+ margin-bottom: 45px;
90
+ margin-top: 35px;
91
+ text-align: center;
92
+ border-bottom: 1px solid #e5e5e5;
93
+ }
94
+ .footer>p {
95
+ font-size: .8rem;
96
+ display: inline-block;
97
+ padding: 0 10px;
98
+ transform: translateY(10px);
99
+ background: white;
100
+ }
101
+ .dark .footer {
102
+ border-color: #303030;
103
+ }
104
+ .dark .footer>p {
105
+ background: #0b0f19;
106
+ }
107
+ .acknowledgments h4{
108
+ margin: 1.25em 0 .25em 0;
109
+ font-weight: bold;
110
+ font-size: 115%;
111
+ }
112
+ .animate-spin {
113
+ animation: spin 1s linear infinite;
114
+ }
115
+ @keyframes spin {
116
+ from {
117
+ transform: rotate(0deg);
118
+ }
119
+ to {
120
+ transform: rotate(360deg);
121
+ }
122
+ }
123
+ #share-btn-container {
124
+ display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
125
+ margin-top: 10px;
126
+ margin-left: auto;
127
+ }
128
+ #share-btn {
129
+ all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
130
+ }
131
+ #share-btn * {
132
+ all: unset;
133
+ }
134
+ #share-btn-container div:nth-child(-n+2){
135
+ width: auto !important;
136
+ min-height: 0px !important;
137
+ }
138
+ #share-btn-container .wrap {
139
+ display: none !important;
140
+ }
141
+
142
+ .gr-form{
143
+ flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
144
+ }
145
+ #prompt-container{
146
+ gap: 0;
147
+ }
148
+ #prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
149
+ #component-16{border-top-width: 1px!important;margin-top: 1em}
150
+ .image_duplication{position: absolute; width: 100px; left: 50px}
151
+ """
152
 
153
+ block = gr.Blocks(css=css)
154
 
155
+ with block:
156
+ gr.HTML(
157
+ """
158
+ <div style="text-align: center; margin: 0 auto;">
159
+ <div
160
+ style="
161
+ display: inline-flex;
162
+ align-items: center;
163
+ gap: 0.8rem;
164
+ font-size: 1.75rem;
165
+ "
166
+ >
167
+
168
+ <h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
169
+ Art Search Engine
170
+ </h1>
171
+ </div>
172
+ <p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
173
+ Read the article <a style="text-decoration: underline;" href="https://huggingface.co/spaces/stabilityai/stable-diffusion-1">Searching Art through Deep Learning</a>
174
+ </p>
175
+ </div>
176
+ """
177
+ )
178
+ with gr.Group():
179
+ with gr.Box():
180
+ with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
181
+ with gr.Column():
182
+ text = gr.Textbox(
183
+ label="Describe A Scene.",
184
+ show_label=False,
185
+ max_lines=1,
186
+ placeholder="Describe A Scene.",
187
+ elem_id="prompt-text-input",
188
+ ).style(
189
+ border=(True, False, True, True),
190
+ rounded=(True, False, False, True),
191
+ container=False,
192
+ )
193
+ btn = gr.Button("Search Art").style(
194
+ margin=False,
195
+ rounded=(False, True, True, False),
196
+ full_width=False,
197
+ )
198
+
199
+ gallery = gr.Gallery(
200
+ label="Art Pieces", show_label=False, elem_id="gallery"
201
+ ).style(grid=[2], height="auto")
202
+ btn.click(get_images, inputs=text, outputs=gallery, postprocess=False)
203
+
204
+ gr.HTML(
205
+ """
206
+ <div class="footer">
207
+ <p>Model by <a href="https://www.meet-drift.ai/" style="text-decoration: underline;" target="_blank">Drift</a>
208
+ </p>
209
+ </div>
210
+ """
211
+ )
212
 
213
+ block.launch()
 
poetry.lock CHANGED
The diff for this file is too large to render. See raw diff
 
pyproject.toml CHANGED
@@ -9,6 +9,9 @@ readme = "README.md"
9
  python = "^3.8"
10
  gradio = "^3.12.0"
11
  Pillow = "^9.3.0"
 
 
 
12
 
13
 
14
  [build-system]
 
9
  python = "^3.8"
10
  gradio = "^3.12.0"
11
  Pillow = "^9.3.0"
12
+ python-dotenv = "^0.21.0"
13
+ setuptools = "^65.6.3"
14
+ distribute = "^0.7.3"
15
 
16
 
17
  [build-system]
requirements.txt CHANGED
@@ -44,6 +44,7 @@ pydub==0.25.1
44
  PyNaCl==1.5.0
45
  pyparsing==3.0.9
46
  python-dateutil==2.8.2
 
47
  python-multipart==0.0.5
48
  pytz==2022.6
49
  PyYAML==6.0
 
44
  PyNaCl==1.5.0
45
  pyparsing==3.0.9
46
  python-dateutil==2.8.2
47
+ python-dotenv==0.21.0
48
  python-multipart==0.0.5
49
  pytz==2022.6
50
  PyYAML==6.0