Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ from PIL import ImageFont
|
|
7 |
import gradio as gr
|
8 |
from datasets import load_dataset
|
9 |
|
10 |
-
dataset = load_dataset("chansung/testds")
|
11 |
print(dataset)
|
12 |
|
13 |
images = []
|
@@ -15,21 +14,23 @@ titles = []
|
|
15 |
stories = []
|
16 |
|
17 |
def add_title(image, title):
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
|
27 |
def gallery_select(gallery, evt: gr.SelectData):
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
|
|
|
|
33 |
for row in dataset['train']:
|
34 |
base64_image = row['image']
|
35 |
base64_decoded = base64.b64decode(base64_image)
|
@@ -38,8 +39,11 @@ with gr.Blocks() as demo:
|
|
38 |
titles.append(row['title'])
|
39 |
stories.append(row['story'])
|
40 |
images.append(add_title(image, row['title']))
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
gallery.select(
|
45 |
fn=gallery_select,
|
|
|
7 |
import gradio as gr
|
8 |
from datasets import load_dataset
|
9 |
|
|
|
10 |
print(dataset)
|
11 |
|
12 |
images = []
|
|
|
14 |
stories = []
|
15 |
|
16 |
def add_title(image, title):
|
17 |
+
dr = ImageDraw.Draw(image)
|
18 |
|
19 |
+
myFont = ImageFont.truetype('arial_bold.ttf', 30)
|
20 |
+
_, _, w, h = dr.textbbox((0, 0), title, font=myFont)
|
21 |
+
dr.rectangle([(0, image.height-80), (image.width, (image.height-80)+h)], fill="white", outline="white")
|
22 |
+
dr.text(((image.width-w)/2, image.height-80), title, font=myFont, fill=(0, 0, 0))
|
23 |
|
24 |
+
return image
|
25 |
|
26 |
def gallery_select(gallery, evt: gr.SelectData):
|
27 |
+
print(evt.value)
|
28 |
+
print(evt.index)
|
29 |
+
print(evt.target)
|
30 |
|
31 |
+
def get_gallery():
|
32 |
+
dataset = load_dataset("chansung/testds")
|
33 |
+
|
34 |
for row in dataset['train']:
|
35 |
base64_image = row['image']
|
36 |
base64_decoded = base64.b64decode(base64_image)
|
|
|
39 |
titles.append(row['title'])
|
40 |
stories.append(row['story'])
|
41 |
images.append(add_title(image, row['title']))
|
42 |
+
|
43 |
+
return images
|
44 |
+
|
45 |
+
with gr.Blocks() as demo:
|
46 |
+
gallery = gr.Gallery(get_gallery, columns=10, height=500, container=False)
|
47 |
|
48 |
gallery.select(
|
49 |
fn=gallery_select,
|