johnbradley commited on
Commit
9293447
β€’
1 Parent(s): 938a85a

Use article for details and add examples

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -6,6 +6,19 @@ import gradio as gr
6
  import cv2
7
  from drexel_metadata.gen_metadata import gen_metadata
8
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
 
11
  def create_temp_file_path(prefix, suffix):
@@ -13,7 +26,7 @@ def create_temp_file_path(prefix, suffix):
13
  return tmpfile.name
14
 
15
 
16
- def run_inference(markdown, input_img):
17
  # input_mg: NumPy array with the shape (width, height, 3)
18
 
19
  # Save input_mg as a temporary file
@@ -39,12 +52,10 @@ def read_app_header_markdown():
39
  with open('app_header.md') as infile:
40
  return infile.read()
41
 
42
-
43
  dm_app = gr.Interface(
44
  fn=run_inference,
45
  # Input shows markdown explaining and app and a single image upload panel
46
  inputs=[
47
- gr.Markdown(read_app_header_markdown()),
48
  gr.Image()
49
  ],
50
  # Output consists of a visualization image, a masked image, and JSON metadata
@@ -53,7 +64,9 @@ dm_app = gr.Interface(
53
  gr.Image(label='mask'),
54
  gr.JSON(label="JSON metadata")
55
  ],
56
- allow_flagging="never" # Do not save user's results or prompt for users to save the results
 
 
57
  )
58
  dm_app.launch()
59
 
 
6
  import cv2
7
  from drexel_metadata.gen_metadata import gen_metadata
8
  from PIL import Image
9
+ import urllib.request
10
+
11
+
12
+ EXAMPLE_URLS = [
13
+ 'http://www.tubri.org/HDR/INHS/INHS_FISH_59422.jpg',
14
+ 'http://www.tubri.org/HDR/INHS/INHS_FISH_76560.jpg'
15
+ ]
16
+ EXAMPLES = []
17
+ for example_url in EXAMPLE_URLS:
18
+ file_name = os.path.basename(example_url)
19
+ urllib.request.urlretrieve(example_url, file_name)
20
+ # According to the docs examples should be a nested list
21
+ EXAMPLES.append([file_name])
22
 
23
 
24
  def create_temp_file_path(prefix, suffix):
 
26
  return tmpfile.name
27
 
28
 
29
+ def run_inference(input_img):
30
  # input_mg: NumPy array with the shape (width, height, 3)
31
 
32
  # Save input_mg as a temporary file
 
52
  with open('app_header.md') as infile:
53
  return infile.read()
54
 
 
55
  dm_app = gr.Interface(
56
  fn=run_inference,
57
  # Input shows markdown explaining and app and a single image upload panel
58
  inputs=[
 
59
  gr.Image()
60
  ],
61
  # Output consists of a visualization image, a masked image, and JSON metadata
 
64
  gr.Image(label='mask'),
65
  gr.JSON(label="JSON metadata")
66
  ],
67
+ article=read_app_header_markdown(),
68
+ allow_flagging="never", # Do not save user's results or prompt for users to save the results
69
+ examples=EXAMPLES,
70
  )
71
  dm_app.launch()
72