23A066X commited on
Commit
d73cc9d
1 Parent(s): e6dda01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -17,3 +17,42 @@ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
17
  iface.launch()
18
 
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  iface.launch()
18
 
19
 
20
+
21
+ PATH_TO_LABELS = 'label_map.pbtxt'
22
+ category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
23
+
24
+ def pil_image_as_numpy_array(pilimg):
25
+
26
+ img_array = tf.keras.utils.img_to_array(pilimg)
27
+ img_array = np.expand_dims(img_array, axis=0)
28
+ return img_array
29
+
30
+ def load_image_into_numpy_array(path):
31
+
32
+ image = None
33
+ image_data = tf.io.gfile.GFile(path, 'rb').read()
34
+ image = Image.open(BytesIO(image_data))
35
+ return pil_image_as_numpy_array(image)
36
+
37
+ def load_model():
38
+ download_dir = snapshot_download()
39
+ saved_model_dir = os.path.join(download_dir, "saved_model.pb")
40
+ detection_model = tf.saved_model.load(saved_model_dir)
41
+ return detection_model
42
+
43
+
44
+ def predict(pilimg):
45
+
46
+ image_np = pil_image_as_numpy_array(pilimg)
47
+ return predict2(image_np)
48
+
49
+ detection_model = load_model()
50
+ # pil_image = Image.open(image_path)
51
+ # image_arr = pil_image_as_numpy_array(pil_image)
52
+ # predicted_img = predict(image_arr)
53
+ # predicted_img.save('predicted.jpg')
54
+
55
+ gr.Interface(fn=predict,
56
+ inputs=gr.Image(type="pil"),
57
+ outputs=gr.Image(type="pil")
58
+ ).launch(share=True)