Spaces:
Running on CPU Upgrade

Wauplin HF staff commited on
Commit
78c89d4
1 Parent(s): b605cb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -1,10 +1,13 @@
1
  import gradio as gr
2
  from datasets import load_dataset
3
 
 
4
  import re
5
  import os
6
  import requests
 
7
 
 
8
  from share_btn import community_icon_html, loading_icon_html, share_js
9
 
10
  # TODO
@@ -12,7 +15,7 @@ from share_btn import community_icon_html, loading_icon_html, share_js
12
  #word_list = word_list_dataset["train"]['text']
13
  word_list = []
14
 
15
- def infer(prompt, negative="low_quality", scale=7):
16
  for filter in word_list:
17
  if re.search(rf"\b{filter}\b", prompt):
18
  raise gr.Error("Unsafe content found. Please try again with different prompts.")
@@ -24,6 +27,20 @@ def infer(prompt, negative="low_quality", scale=7):
24
  for image in images_request.json()["images"]:
25
  image_b64 = (f"data:image/jpeg;base64,{image}")
26
  images.append(image_b64)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  return images, gr.update(visible=True)
29
 
@@ -150,7 +167,7 @@ css = """
150
  .image_duplication{position: absolute; width: 100px; left: 50px}
151
  """
152
 
153
- block = gr.Blocks(css=css)
154
 
155
  examples = [
156
  [
@@ -299,7 +316,12 @@ Despite how impressive being able to turn text into image is, beware that this m
299
  </div>
300
  """
301
  )
302
-
303
 
304
- block.queue(concurrency_count=4, max_size=10).launch()
305
- #block.launch(server_name="0.0.0.0")
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from datasets import load_dataset
3
 
4
+ import base64
5
  import re
6
  import os
7
  import requests
8
+ from io import BytesIO
9
 
10
+ import user_history
11
  from share_btn import community_icon_html, loading_icon_html, share_js
12
 
13
  # TODO
 
15
  #word_list = word_list_dataset["train"]['text']
16
  word_list = []
17
 
18
+ def infer(prompt, negative="low_quality", scale=7, profile: gr.OAuthProfile | None):
19
  for filter in word_list:
20
  if re.search(rf"\b{filter}\b", prompt):
21
  raise gr.Error("Unsafe content found. Please try again with different prompts.")
 
27
  for image in images_request.json()["images"]:
28
  image_b64 = (f"data:image/jpeg;base64,{image}")
29
  images.append(image_b64)
30
+
31
+ if profile is not None: # avoid conversion on non-logged-in users
32
+ for image in images:
33
+ pil_image = Image.open(BytesIO(base64.b64decode(image)))
34
+ user_history.save_image( # save images + metadata to user history
35
+ label=prompt,
36
+ image=pil_image,
37
+ profile=profile,
38
+ metadata={
39
+ "prompt": prompt,
40
+ "negative_prompt": negative,
41
+ "guidance_scale": scale,
42
+ },
43
+ )
44
 
45
  return images, gr.update(visible=True)
46
 
 
167
  .image_duplication{position: absolute; width: 100px; left: 50px}
168
  """
169
 
170
+ block = gr.Blocks()
171
 
172
  examples = [
173
  [
 
316
  </div>
317
  """
318
  )
 
319
 
320
+ with gr.Blocks(css=css) as block_with_history:
321
+ with gr.Tab("Demo"):
322
+ block.render()
323
+ with gr.Tab("Past generations"):
324
+ user_history.render()
325
+
326
+ block_with_history.queue(concurrency_count=4, max_size=10).launch()
327
+ #block_with_history.launch(server_name="0.0.0.0")