chansung commited on
Commit
5c3a233
·
1 Parent(s): e0f7776

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
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
- dr = ImageDraw.Draw(image)
19
 
20
- myFont = ImageFont.truetype('arial_bold.ttf', 30)
21
- _, _, w, h = dr.textbbox((0, 0), title, font=myFont)
22
- dr.rectangle([((image.width-w)/2, image.height-80), (((image.width-w)/2)+w, (image.height-80)+h)], fill="white", outline="white")
23
- dr.text(((image.width-w)/2, image.height-80), title, font=myFont, fill=(0, 0, 0))
24
 
25
- return image
26
 
27
  def gallery_select(gallery, evt: gr.SelectData):
28
- print(evt.value)
29
- print(evt.index)
30
- print(evt.target)
31
 
32
- with gr.Blocks() as demo:
 
 
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
- gallery = gr.Gallery(images, columns=10, height=500, container=False)
 
 
 
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,