Wei Ni commited on
Commit
87fab7c
1 Parent(s): 8f3575e

feat: included app

Browse files
Files changed (2) hide show
  1. app/app.py +28 -0
  2. broken_windows.ipynb +145 -2
app/app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../broken_windows.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_broken', 'classify_image']
5
+
6
+ # %% ../broken_windows.ipynb 19
7
+ from fastai.vision.all import *
8
+ import gradio as gr
9
+
10
+ def is_broken(x): return x[0].isupper()
11
+
12
+ # %% ../broken_windows.ipynb 20
13
+ learn = load_learner('model.pkl')
14
+
15
+ # %% ../broken_windows.ipynb 21
16
+ categories = ('Broken window', 'Not broken window')
17
+
18
+ def classify_image(img):
19
+ pred, idx, probs = learn.predict(img)
20
+ return dict(zip(categories, map(float, probs)))
21
+
22
+ # %% ../broken_windows.ipynb 22
23
+ image = gr.Image()
24
+ label = gr.Label()
25
+ examples = ['window.jpg', 'broken_window.jpg']
26
+
27
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
28
+ intf.launch(inline=False)
broken_windows.ipynb CHANGED
@@ -12,10 +12,22 @@
12
  },
13
  {
14
  "cell_type": "code",
15
- "execution_count": 1,
16
  "id": "a744c5f1-de6e-474a-9605-058b0bfdb6e3",
17
  "metadata": {},
18
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
19
  "source": [
20
  "from fastcore.all import *\n",
21
  "import time\n",
@@ -761,6 +773,137 @@
761
  "source": [
762
  "learn.export(\"model.pkl\")"
763
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
764
  }
765
  ],
766
  "metadata": {
 
12
  },
13
  {
14
  "cell_type": "code",
15
+ "execution_count": 18,
16
  "id": "a744c5f1-de6e-474a-9605-058b0bfdb6e3",
17
  "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "ename": "ModuleNotFoundError",
21
+ "evalue": "No module named 'ndev'",
22
+ "output_type": "error",
23
+ "traceback": [
24
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
25
+ "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
26
+ "Cell \u001b[1;32mIn[18], line 4\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtime\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtimm\u001b[39;00m\n\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mndev\u001b[39;00m\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msearch_images\u001b[39m(term, max_images \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m250\u001b[39m):\n\u001b[0;32m 7\u001b[0m url \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://duckduckgo.com/\u001b[39m\u001b[38;5;124m\"\u001b[39m\n",
27
+ "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'ndev'"
28
+ ]
29
+ }
30
+ ],
31
  "source": [
32
  "from fastcore.all import *\n",
33
  "import time\n",
 
773
  "source": [
774
  "learn.export(\"model.pkl\")"
775
  ]
776
+ },
777
+ {
778
+ "cell_type": "code",
779
+ "execution_count": 27,
780
+ "id": "83e6d420-50a9-440f-a176-62ae5c84c9e2",
781
+ "metadata": {},
782
+ "outputs": [],
783
+ "source": [
784
+ "#|export\n",
785
+ "from fastai.vision.all import *\n",
786
+ "import gradio as gr\n",
787
+ "\n",
788
+ "def is_broken(x): return x[0].isupper()"
789
+ ]
790
+ },
791
+ {
792
+ "cell_type": "code",
793
+ "execution_count": 28,
794
+ "id": "c8348e8a-596f-4048-963d-5e9a22f7b8c8",
795
+ "metadata": {},
796
+ "outputs": [],
797
+ "source": [
798
+ "#|export\n",
799
+ "learn = load_learner('model.pkl')"
800
+ ]
801
+ },
802
+ {
803
+ "cell_type": "code",
804
+ "execution_count": 29,
805
+ "id": "226796e5-f291-43e6-959b-33f5f1576f9e",
806
+ "metadata": {},
807
+ "outputs": [],
808
+ "source": [
809
+ "#|export\n",
810
+ "categories = ('Broken window', 'Not broken window')\n",
811
+ "\n",
812
+ "def classify_image(img):\n",
813
+ " pred, idx, probs = learn.predict(img)\n",
814
+ " return dict(zip(categories, map(float, probs)))"
815
+ ]
816
+ },
817
+ {
818
+ "cell_type": "code",
819
+ "execution_count": 34,
820
+ "id": "bf76799e-8eaa-4842-b0aa-128cfd0f2e5a",
821
+ "metadata": {},
822
+ "outputs": [
823
+ {
824
+ "name": "stdout",
825
+ "output_type": "stream",
826
+ "text": [
827
+ "Running on local URL: http://127.0.0.1:7864\n",
828
+ "\n",
829
+ "To create a public link, set `share=True` in `launch()`.\n"
830
+ ]
831
+ },
832
+ {
833
+ "data": {
834
+ "text/plain": []
835
+ },
836
+ "execution_count": 34,
837
+ "metadata": {},
838
+ "output_type": "execute_result"
839
+ },
840
+ {
841
+ "data": {
842
+ "text/html": [
843
+ "\n",
844
+ "<style>\n",
845
+ " /* Turns off some styling */\n",
846
+ " progress {\n",
847
+ " /* gets rid of default border in Firefox and Opera. */\n",
848
+ " border: none;\n",
849
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
850
+ " background-size: auto;\n",
851
+ " }\n",
852
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
853
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
854
+ " }\n",
855
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
856
+ " background: #F44336;\n",
857
+ " }\n",
858
+ "</style>\n"
859
+ ],
860
+ "text/plain": [
861
+ "<IPython.core.display.HTML object>"
862
+ ]
863
+ },
864
+ "metadata": {},
865
+ "output_type": "display_data"
866
+ },
867
+ {
868
+ "data": {
869
+ "text/html": [],
870
+ "text/plain": [
871
+ "<IPython.core.display.HTML object>"
872
+ ]
873
+ },
874
+ "metadata": {},
875
+ "output_type": "display_data"
876
+ }
877
+ ],
878
+ "source": [
879
+ "#|export\n",
880
+ "image = gr.Image()\n",
881
+ "label = gr.Label()\n",
882
+ "examples = ['odd_broken_window.jpg', 'broken_window.jpg', \"window_error.jpg\"]\n",
883
+ "\n",
884
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
885
+ "intf.launch(inline=False)"
886
+ ]
887
+ },
888
+ {
889
+ "cell_type": "code",
890
+ "execution_count": null,
891
+ "id": "12bfec97-5699-4fe8-ba7b-3a73fb09737f",
892
+ "metadata": {},
893
+ "outputs": [],
894
+ "source": [
895
+ "import nbdev"
896
+ ]
897
+ },
898
+ {
899
+ "cell_type": "code",
900
+ "execution_count": 35,
901
+ "id": "2bdbc123-fda4-4311-9056-f72924770cdc",
902
+ "metadata": {},
903
+ "outputs": [],
904
+ "source": [
905
+ "nbdev.export.nb_export('broken_windows.ipynb', 'app')"
906
+ ]
907
  }
908
  ],
909
  "metadata": {