Spaces:
Runtime error
Runtime error
Vincent Claes
commited on
Commit
·
59df02f
1
Parent(s):
113288d
add mapping for artist
Browse files- app.py +10 -3
- mapping.json +0 -0
app.py
CHANGED
@@ -1,8 +1,12 @@
|
|
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",
|
@@ -19,12 +23,15 @@ def get_images(text):
|
|
19 |
json={"data": text},
|
20 |
)
|
21 |
images = []
|
22 |
-
|
|
|
|
|
|
|
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 {
|
@@ -198,7 +205,7 @@ with block:
|
|
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(
|
|
|
1 |
import os
|
2 |
+
import json
|
3 |
import requests
|
4 |
|
5 |
import gradio as gr
|
6 |
|
7 |
+
with open("mapping.json", "r") as f:
|
8 |
+
mapping = json.load(f)
|
9 |
+
|
10 |
def get_images(text):
|
11 |
headers = {
|
12 |
"Content-Type": "application/json",
|
|
|
23 |
json={"data": text},
|
24 |
)
|
25 |
images = []
|
26 |
+
response_json = response.json()
|
27 |
+
image_data = response_json["image"]
|
28 |
+
image_label = [mapping[str(id_)]for id_ in response_json["id"] ]
|
29 |
+
|
30 |
for image in image_data:
|
31 |
# got this from https://huggingface.co/spaces/stabilityai/stable-diffusion/blob/main/app.py
|
32 |
image_b64 = (f"data:image/jpeg;base64,{image}")
|
33 |
images.append(image_b64)
|
34 |
+
return tuple(zip(images, image_label))
|
35 |
|
36 |
css = """
|
37 |
.gradio-container {
|
|
|
205 |
|
206 |
gallery = gr.Gallery(
|
207 |
label="Art Pieces", show_label=False, elem_id="gallery"
|
208 |
+
).style(grid=[2], height="auto", container=True)
|
209 |
btn.click(get_images, inputs=text, outputs=gallery, postprocess=False)
|
210 |
|
211 |
gr.HTML(
|
mapping.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|