Abhishek Gola commited on
Commit
4712951
·
1 Parent(s): de320a0

Added samples

Browse files
Files changed (4) hide show
  1. .gitattributes +5 -0
  2. app.py +38 -9
  3. examples/baboon.jpg +3 -0
  4. examples/squirrel_cls.jpg +3 -0
.gitattributes CHANGED
@@ -14,6 +14,11 @@
14
  *.npy filter=lfs diff=lfs merge=lfs -text
15
  *.npz filter=lfs diff=lfs merge=lfs -text
16
  *.onnx filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
17
  *.ot filter=lfs diff=lfs merge=lfs -text
18
  *.parquet filter=lfs diff=lfs merge=lfs -text
19
  *.pb filter=lfs diff=lfs merge=lfs -text
 
14
  *.npy filter=lfs diff=lfs merge=lfs -text
15
  *.npz filter=lfs diff=lfs merge=lfs -text
16
  *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
18
+ *.jpg filter=lfs diff=lfs merge=lfs -text
19
+ *.gif filter=lfs diff=lfs merge=lfs -text
20
+ *.png filter=lfs diff=lfs merge=lfs -text
21
+ *.webp filter=lfs diff=lfs merge=lfs -te
22
  *.ot filter=lfs diff=lfs merge=lfs -text
23
  *.parquet filter=lfs diff=lfs merge=lfs -text
24
  *.pb filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -22,15 +22,44 @@ def classify_image(input_image):
22
  result_str = "\n".join(f"{label}" for label in result)
23
  return result_str
24
 
25
- # Gradio Interface
26
- demo = gr.Interface(
27
- fn=classify_image,
28
- inputs=gr.Image(type="numpy", label="Upload Image"),
29
- outputs=gr.Textbox(label="Top Prediction(s)"),
30
- title="Image Classification with MobileNet (OpenCV DNN)",
31
- allow_flagging="never",
32
- description="Upload an image to classify using a MobileNet model loaded with OpenCV DNN."
33
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  if __name__ == "__main__":
36
  demo.launch()
 
22
  result_str = "\n".join(f"{label}" for label in result)
23
  return result_str
24
 
25
+ def clear_output_on_change(img):
26
+ return gr.update(value="")
27
+
28
+ def clear_all():
29
+ return None, None
30
+
31
+ with gr.Blocks(css='''.example * {
32
+ font-style: italic;
33
+ font-size: 18px !important;
34
+ color: #0ea5e9 !important;
35
+ }''') as demo:
36
+
37
+ gr.Markdown("### Image Classification with MobileNet (OpenCV DNN)")
38
+ gr.Markdown("Upload an image to classify using a MobileNet model loaded with OpenCV DNN.")
39
+
40
+ with gr.Row():
41
+ image_input = gr.Image(type="numpy", label="Upload Image")
42
+ output_box = gr.Textbox(label="Top Prediction(s)")
43
+
44
+ # Clear output when new image is uploaded
45
+ image_input.change(fn=clear_output_on_change, inputs=image_input, outputs=output_box)
46
+
47
+ with gr.Row():
48
+ submit_btn = gr.Button("Submit", variant="primary")
49
+ clear_btn = gr.Button("Clear")
50
+
51
+ submit_btn.click(fn=classify_image, inputs=image_input, outputs=output_box)
52
+ clear_btn.click(fn=clear_all, outputs=[image_input, output_box])
53
+
54
+ gr.Markdown("Click on any example to try it.", elem_classes=["example"])
55
+
56
+ gr.Examples(
57
+ examples=[
58
+ ["examples/squirrel_cls.jpg"],
59
+ ["examples/baboon.jpg"]
60
+ ],
61
+ inputs=image_input
62
+ )
63
 
64
  if __name__ == "__main__":
65
  demo.launch()
examples/baboon.jpg ADDED

Git LFS Details

  • SHA256: 1a1dd18d78eec44420af3b0b7f08ee3d41c982916cae3ce203d7ff35d754cc0f
  • Pointer size: 131 Bytes
  • Size of remote file: 180 kB
examples/squirrel_cls.jpg ADDED

Git LFS Details

  • SHA256: 20bb6e8ae96918a36c9886b6d48e54eedeb3948591e1485c206bc1dc60c8dc8b
  • Pointer size: 130 Bytes
  • Size of remote file: 62.3 kB