Spaces:
Build error
Build error
Commit
·
0b95222
1
Parent(s):
fa64015
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,6 +42,14 @@ def normalize_2d(matrix):
|
|
| 42 |
return matrix
|
| 43 |
|
| 44 |
# Create predict function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
def predict(img):
|
| 46 |
|
| 47 |
start_time = timer()
|
|
@@ -68,7 +76,7 @@ def predict(img):
|
|
| 68 |
pred_time = round(timer() - start_time, 5)
|
| 69 |
|
| 70 |
# Return the prediction dictionary and prediction time
|
| 71 |
-
return pred_labels_and_probs, pred_time
|
| 72 |
|
| 73 |
### 4. Gradio app ###
|
| 74 |
|
|
@@ -89,16 +97,24 @@ outputs_image = [
|
|
| 89 |
]
|
| 90 |
|
| 91 |
# Create the Gradio demo
|
| 92 |
-
|
| 93 |
-
inputs=
|
| 94 |
outputs=[gr.Label(num_top_classes=2, label="Predictions"), # what are the outputs?
|
| 95 |
-
gr.Number(label="Prediction time (s)")
|
| 96 |
-
|
| 97 |
# Create examples list from "examples/" directory
|
| 98 |
examples=example_list,
|
| 99 |
title=title,
|
| 100 |
description=description,
|
| 101 |
article=article)
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
# Launch the demo!
|
| 104 |
demo.launch()
|
|
|
|
| 42 |
return matrix
|
| 43 |
|
| 44 |
# Create predict function
|
| 45 |
+
|
| 46 |
+
# Detect the image
|
| 47 |
+
|
| 48 |
+
def detect(imagepath):
|
| 49 |
+
|
| 50 |
+
pix=model.predict(imagepath, confidence=40, overlap=30)
|
| 51 |
+
return pix
|
| 52 |
+
|
| 53 |
def predict(img):
|
| 54 |
|
| 55 |
start_time = timer()
|
|
|
|
| 76 |
pred_time = round(timer() - start_time, 5)
|
| 77 |
|
| 78 |
# Return the prediction dictionary and prediction time
|
| 79 |
+
return pred_labels_and_probs, pred_time
|
| 80 |
|
| 81 |
### 4. Gradio app ###
|
| 82 |
|
|
|
|
| 97 |
]
|
| 98 |
|
| 99 |
# Create the Gradio demo
|
| 100 |
+
app1 = gr.Interface(fn=predict, # mapping function from input to output
|
| 101 |
+
inputs=gr.Image(type="pil"), # what are the inputs?
|
| 102 |
outputs=[gr.Label(num_top_classes=2, label="Predictions"), # what are the outputs?
|
| 103 |
+
gr.Number(label="Prediction time (s)")
|
| 104 |
+
], # our fn has two outputs, therefore we have two outputs
|
| 105 |
# Create examples list from "examples/" directory
|
| 106 |
examples=example_list,
|
| 107 |
title=title,
|
| 108 |
description=description,
|
| 109 |
article=article)
|
| 110 |
|
| 111 |
+
app2=gr.Interface(fn=detect,
|
| 112 |
+
inputs=inputs_image,
|
| 113 |
+
outputs=outputs_image,
|
| 114 |
+
title=title)
|
| 115 |
+
|
| 116 |
+
demo = gr.TabbedInterface([app1, app2], ["Classify", "Detect"])
|
| 117 |
+
|
| 118 |
+
|
| 119 |
# Launch the demo!
|
| 120 |
demo.launch()
|