trifonova commited on
Commit
2e91066
·
1 Parent(s): de34e36

Clean up commented out code

Browse files
Files changed (2) hide show
  1. app.py +2 -98
  2. fair.py +0 -1
app.py CHANGED
@@ -1,31 +1,13 @@
1
  import gradio as gr
2
- #from datasets import load_dataset
3
- from PIL import Image
4
- import re
5
- import os
6
- import requests
7
  import numpy as np
8
 
9
  from fair import text_to_image
10
 
11
- from share_btn import community_icon_html, loading_icon_html, share_js
12
-
13
  model_id = "runwayml/stable-diffusion-v1-5"
14
  device = "cuda"
15
 
16
- #word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
17
- #word_list = word_list_dataset["train"]['text']
18
-
19
- #is_gpu_busy = False
20
  def infer(prompt):
21
- #global is_gpu_busy
22
- samples = 4
23
- steps = 50
24
- scale = 7.5
25
- # for filter in word_list:
26
- # if re.search(rf"\b{filter}\b", prompt):
27
- # raise gr.Error("Unsafe content found. Please try again with different prompts.")
28
- #
29
  image_file = text_to_image(prompt)
30
  image = np.array(Image.open(image_file).convert('RGB'))
31
  images = [image]
@@ -155,44 +137,6 @@ css = """
155
 
156
  block = gr.Blocks(css=css)
157
 
158
- examples = [
159
- [
160
- 'The spirit of a tamagotchi wandering in the city of Paris',
161
- # 4,
162
- # 45,
163
- # 7.5,
164
- # 1024,
165
- ],
166
- [
167
- 'A delicious ceviche cheesecake slice',
168
- # 4,
169
- # 45,
170
- # 7,
171
- # 1024,
172
- ],
173
- [
174
- 'A pao de queijo foodcart in front of a japanese castle',
175
- # 4,
176
- # 45,
177
- # 7,
178
- # 1024,
179
- ],
180
- [
181
- 'alone in the amusement park by Edward Hopper',
182
- # 4,
183
- # 45,
184
- # 7,
185
- # 1024,
186
- ],
187
- [
188
- "A large cabin on top of a sunny mountain in the style of Dreamworks, artstation",
189
- # 4,
190
- # 45,
191
- # 7,
192
- # 1024,
193
- ],
194
- ]
195
-
196
 
197
  with block:
198
  gr.HTML(
@@ -235,55 +179,15 @@ with block:
235
  rounded=(False, True, True, False),
236
  full_width=False,
237
  )
238
- # gallery = gr.Image(type="filepath").style(grid=[2], height="auto")
239
  gallery = gr.Gallery(
240
  label="Generated images", show_label=False, elem_id="gallery"
241
  ).style(grid=[1], height="auto")
242
 
243
- # with gr.Group(elem_id="container-advanced-btns"):
244
- # advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
245
- # with gr.Group(elem_id="share-btn-container"):
246
- # community_icon = gr.HTML(community_icon_html)
247
- # loading_icon = gr.HTML(loading_icon_html)
248
- # share_button = gr.Button("Share to community", elem_id="share-btn")
249
- #
250
- # with gr.Row(elem_id="advanced-options"):
251
- # gr.Markdown("Advanced settings are temporarily unavailable")
252
- # samples = gr.Slider(label="Images", minimum=1, maximum=4, value=4, step=1)
253
- # steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=45, step=1)
254
- # scale = gr.Slider(
255
- # label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
256
- # )
257
- # seed = gr.Slider(
258
- # label="Seed",
259
- # minimum=0,
260
- # maximum=2147483647,
261
- # step=1,
262
- # randomize=True,
263
- # )
264
-
265
- #ex = gr.Examples(examples=examples, fn=infer, inputs=text, outputs=[gallery], cache_examples=True, postprocess=False)
266
- #ex.dataset.headers = [""]
267
 
268
  text.submit(infer, inputs=text, outputs=[gallery])
269
  btn.click(infer, inputs=text, outputs=[gallery])
270
 
271
- # advanced_button.click(
272
- # None,
273
- # [],
274
- # text,
275
- # _js="""
276
- # () => {
277
- # const options = document.querySelector("body > gradio-app").querySelector("#advanced-options");
278
- # options.style.display = ["none", ""].includes(options.style.display) ? "flex" : "none";
279
- # }""",
280
- # )
281
- # share_button.click(
282
- # None,
283
- # [],
284
- # [],
285
- # _js=share_js,
286
- # )
287
  gr.HTML(
288
  """
289
  <div class="footer">
 
1
  import gradio as gr
2
+ from PIL import Image
 
 
 
 
3
  import numpy as np
4
 
5
  from fair import text_to_image
6
 
 
 
7
  model_id = "runwayml/stable-diffusion-v1-5"
8
  device = "cuda"
9
 
 
 
 
 
10
  def infer(prompt):
 
 
 
 
 
 
 
 
11
  image_file = text_to_image(prompt)
12
  image = np.array(Image.open(image_file).convert('RGB'))
13
  images = [image]
 
137
 
138
  block = gr.Blocks(css=css)
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  with block:
142
  gr.HTML(
 
179
  rounded=(False, True, True, False),
180
  full_width=False,
181
  )
 
182
  gallery = gr.Gallery(
183
  label="Generated images", show_label=False, elem_id="gallery"
184
  ).style(grid=[1], height="auto")
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
  text.submit(infer, inputs=text, outputs=[gallery])
188
  btn.click(infer, inputs=text, outputs=[gallery])
189
 
190
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  gr.HTML(
192
  """
193
  <div class="footer">
fair.py CHANGED
@@ -11,7 +11,6 @@ import tempfile
11
  SERVER_ADRESS="https://faircompute.com:8000/api/v1"
12
  #SERVER_ADRESS="http://localhost:8000/api/v1"
13
  DOCKER_IMAGE="faircompute/stable-diffusion:pytorch-1.13.1-cu116"
14
- #DOCKER_IMAGE="sha256:e06453fe869556ea3e63572a935aed4261337b261fdf7bda370472b0587409a9"
15
 
16
  class FairApiClient:
17
  def __init__(self, server_address: str):
 
11
  SERVER_ADRESS="https://faircompute.com:8000/api/v1"
12
  #SERVER_ADRESS="http://localhost:8000/api/v1"
13
  DOCKER_IMAGE="faircompute/stable-diffusion:pytorch-1.13.1-cu116"
 
14
 
15
  class FairApiClient:
16
  def __init__(self, server_address: str):