23A066X commited on
Commit
6c3df1f
1 Parent(s): bf0820e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -1
app.py CHANGED
@@ -14,4 +14,68 @@ def greet(name):
14
  return "Hello " + name + "!!"
15
 
16
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
17
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  return "Hello " + name + "!!"
15
 
16
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
17
+ iface.launch()
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+ PATH_TO_LABELS = 'data/label_map.pbtxt'
27
+ category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
28
+
29
+ def pil_image_as_numpy_array(pilimg):
30
+ img_array = tf.keras.utils.img_to_array(pilimg)
31
+ return img_array
32
+
33
+ def load_model():
34
+ model_dir = 'saved_model'
35
+ detection_model = tf.saved_model.load(str(model_dir))
36
+ return detection_model
37
+
38
+ def predict(image_np):
39
+ image_np = pil_image_as_numpy_array(image_np)
40
+ image_np = np.expand_dims(image_np, axis=0)
41
+ results = detection_model(image_np)
42
+ result = {key: value.numpy() for key, value in results.items()}
43
+ label_id_offset = 0
44
+ image_np_with_detections = image_np.copy()
45
+ viz_utils.visualize_boxes_and_labels_on_image_array(
46
+ image_np_with_detections[0],
47
+ result['detection_boxes'][0],
48
+ (result['detection_classes'][0] + label_id_offset).astype(int),
49
+ result['detection_scores'][0],
50
+ category_index,
51
+ use_normalized_coordinates=True,
52
+ max_boxes_to_draw=200,
53
+ min_score_thresh=.6,
54
+ agnostic_mode=False,
55
+ line_thickness=2
56
+ )
57
+ result_pil_img = tf.keras.utils.array_to_img(image_np_with_detections[0])
58
+ return result_pil_img
59
+
60
+
61
+
62
+ detection_model = load_model()
63
+
64
+ # Specify paths to example images
65
+ sample_images = [["br_61.jpg"], ["br_61.jpg"],
66
+ ]
67
+
68
+ tab1 = gr.Interface(
69
+ fn=predict,
70
+ inputs=gr.Image(label='Upload an expressway image', type="pil"),
71
+ outputs=gr.Image(type="pil"),
72
+ title='Image Processing',
73
+ examples=sample_images
74
+ )
75
+
76
+
77
+ # Create a Multi Interface with Tabs
78
+ iface = gr.TabbedInterface([tab1], title='Cauliflower and Beetroot Detection via ssd_resnet50_v1_fpn_640x640_coco17_tpu-8')
79
+
80
+ # Launch the interface
81
+ iface.launch(share=True)