Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,16 +35,6 @@ def load_model():
|
|
| 35 |
detection_model = tf.saved_model.load(saved_model_dir)
|
| 36 |
return detection_model
|
| 37 |
|
| 38 |
-
# def load_model2():
|
| 39 |
-
# wget.download("https://nyp-aicourse.s3-ap-southeast-1.amazonaws.com/pretrained-models/balloon_model.tar.gz")
|
| 40 |
-
# tarfile.open("balloon_model.tar.gz").extractall()
|
| 41 |
-
# model_dir = 'saved_model'
|
| 42 |
-
# detection_model = tf.saved_model.load(str(model_dir))
|
| 43 |
-
# return detection_model
|
| 44 |
-
|
| 45 |
-
# samples_folder = 'test_samples
|
| 46 |
-
# image_path = 'test_samples/sample_balloon.jpeg
|
| 47 |
-
#
|
| 48 |
|
| 49 |
def predict(pilimg):
|
| 50 |
|
|
@@ -116,6 +106,7 @@ def detect_video(video):
|
|
| 116 |
# Release resources
|
| 117 |
cap.release()
|
| 118 |
|
|
|
|
| 119 |
REPO_ID = "apailang/mytfodmodel"
|
| 120 |
detection_model = load_model()
|
| 121 |
# pil_image = Image.open(image_path)
|
|
@@ -124,21 +115,39 @@ detection_model = load_model()
|
|
| 124 |
# predicted_img = predict(image_arr)
|
| 125 |
# predicted_img.save('predicted.jpg')
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
a = os.path.join(os.path.dirname(__file__), "data/a.mp4") # Video
|
| 136 |
b = os.path.join(os.path.dirname(__file__), "data/b.mp4") # Video
|
| 137 |
c = os.path.join(os.path.dirname(__file__), "data/c.mp4") # Video
|
| 138 |
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
demo = gr.Interface(
|
| 141 |
-
fn=detect_video
|
| 142 |
inputs=gr.Video(),
|
| 143 |
outputs=gr.Video(),
|
| 144 |
examples=[
|
|
@@ -150,6 +159,4 @@ demo = gr.Interface(
|
|
| 150 |
)
|
| 151 |
|
| 152 |
if __name__ == "__main__":
|
| 153 |
-
demo.launch()
|
| 154 |
-
|
| 155 |
-
|
|
|
|
| 35 |
detection_model = tf.saved_model.load(saved_model_dir)
|
| 36 |
return detection_model
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def predict(pilimg):
|
| 40 |
|
|
|
|
| 106 |
# Release resources
|
| 107 |
cap.release()
|
| 108 |
|
| 109 |
+
|
| 110 |
REPO_ID = "apailang/mytfodmodel"
|
| 111 |
detection_model = load_model()
|
| 112 |
# pil_image = Image.open(image_path)
|
|
|
|
| 115 |
# predicted_img = predict(image_arr)
|
| 116 |
# predicted_img.save('predicted.jpg')
|
| 117 |
|
| 118 |
+
test1 = os.path.join(os.path.dirname(__file__), "data/test1.jpeg")
|
| 119 |
+
test2 = os.path.join(os.path.dirname(__file__), "data/test2.jpeg")
|
| 120 |
+
test3 = os.path.join(os.path.dirname(__file__), "data/test3.jpeg")
|
| 121 |
+
test4 = os.path.join(os.path.dirname(__file__), "data/test4.jpeg")
|
| 122 |
+
test5 = os.path.join(os.path.dirname(__file__), "data/test5.jpeg")
|
| 123 |
+
test6 = os.path.join(os.path.dirname(__file__), "data/test6.jpeg")
|
| 124 |
+
test7 = os.path.join(os.path.dirname(__file__), "data/test7.jpeg")
|
| 125 |
+
test8 = os.path.join(os.path.dirname(__file__), "data/test8.jpeg")
|
| 126 |
+
test9 = os.path.join(os.path.dirname(__file__), "data/test9.jpeg")
|
| 127 |
+
test10 = os.path.join(os.path.dirname(__file__), "data/test10.jpeg")
|
| 128 |
+
test11 = os.path.join(os.path.dirname(__file__), "data/test11.jpeg")
|
| 129 |
+
test12 = os.path.join(os.path.dirname(__file__), "data/test12.jpeg")
|
| 130 |
+
|
| 131 |
+
gr.Interface(fn=predict,
|
| 132 |
+
inputs=gr.Image(type="pil"),
|
| 133 |
+
outputs=gr.Image(type="pil"),
|
| 134 |
+
title="Image Prediction Interface",
|
| 135 |
+
description="Upload a Image for prediction",
|
| 136 |
+
examples=[[test1],[test2],[test3],[test4],[test5],[test6],[test7],[test8],[test9],[test10],[test11],[test12],],
|
| 137 |
+
cache_examples=True
|
| 138 |
+
).launch(share=True)
|
| 139 |
|
| 140 |
|
| 141 |
a = os.path.join(os.path.dirname(__file__), "data/a.mp4") # Video
|
| 142 |
b = os.path.join(os.path.dirname(__file__), "data/b.mp4") # Video
|
| 143 |
c = os.path.join(os.path.dirname(__file__), "data/c.mp4") # Video
|
| 144 |
|
| 145 |
+
basename = Path(video_in_file).stem
|
| 146 |
+
video_out_file = os.path.join('data/detected' + '.mp4')
|
| 147 |
+
samples_folder = 'test_samples'
|
| 148 |
|
| 149 |
demo = gr.Interface(
|
| 150 |
+
fn=lambda x: x, #detect_video
|
| 151 |
inputs=gr.Video(),
|
| 152 |
outputs=gr.Video(),
|
| 153 |
examples=[
|
|
|
|
| 159 |
)
|
| 160 |
|
| 161 |
if __name__ == "__main__":
|
| 162 |
+
demo.launch()
|
|
|
|
|
|