youl commited on
Commit
b5bf50b
·
1 Parent(s): 3b9da9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -35,8 +35,9 @@ def plot_img_bbox(img, target):
35
  cv2.putText(img, label, (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2)
36
 
37
  # Display the image with detections
38
- filename = 'pred.jpg'
39
- cv2.imwrite(filename, img)
 
40
 
41
  # transform image
42
  test_transforms = A.Compose([
@@ -71,15 +72,18 @@ def predict(img) :
71
 
72
  nms_prediction = apply_nms(predictions, iou_thresh=0.1)
73
 
74
- plot_img_bbox(np.array(img), nms_prediction)
75
 
76
- pred = np.array(Image.open("pred.jpg"))
77
 
78
  # Calculate the prediction time
79
  pred_time = round(timer() - start_time, 5)
80
 
81
  # Return the prediction dictionary and prediction time
82
- return pred,pred_time
 
 
 
83
 
84
  ### 4. Gradio app ###
85
  # Create title, description and article strings
@@ -89,13 +93,13 @@ article = "Created by data354."
89
 
90
  # Create examples list from "examples/" directory
91
  example_list = [["examples/" + example] for example in os.listdir("examples")]
92
-
 
 
93
  # Create the Gradio demo
94
  demo = gr.Interface(fn=predict, # mapping function from input to output
95
  inputs=gr.Image(type="pil"), # what are the inputs?
96
- outputs=[gr.Label(label="Predictions"), # what are the outputs?
97
- gr.Number(label="Prediction time (s)")], # our fn has two outputs, therefore we have two outputs
98
- # Create examples list from "examples/" directory
99
  examples=example_list,
100
  title=title,
101
  description=description,
 
35
  cv2.putText(img, label, (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2)
36
 
37
  # Display the image with detections
38
+ #filename = 'pred.jpg'
39
+ #cv2.imwrite(filename, img)
40
+ return img
41
 
42
  # transform image
43
  test_transforms = A.Compose([
 
72
 
73
  nms_prediction = apply_nms(predictions, iou_thresh=0.1)
74
 
75
+ pred = plot_img_bbox(np.array(img), nms_prediction)
76
 
77
+ #pred = np.array(Image.open("pred.jpg"))
78
 
79
  # Calculate the prediction time
80
  pred_time = round(timer() - start_time, 5)
81
 
82
  # Return the prediction dictionary and prediction time
83
+ return pred
84
+
85
+ image = gr.components.Image()
86
+ out_im = gr.components.Image()
87
 
88
  ### 4. Gradio app ###
89
  # Create title, description and article strings
 
93
 
94
  # Create examples list from "examples/" directory
95
  example_list = [["examples/" + example] for example in os.listdir("examples")]
96
+ #[gr.Label(label="Predictions"), # what are the outputs?
97
+ #gr.Number(label="Prediction time (s)")], # our fn has two outputs, therefore we have two outputs
98
+ # Create examples list from "examples/" directory
99
  # Create the Gradio demo
100
  demo = gr.Interface(fn=predict, # mapping function from input to output
101
  inputs=gr.Image(type="pil"), # what are the inputs?
102
+ outputs=out_im
 
 
103
  examples=example_list,
104
  title=title,
105
  description=description,