david-willis-dev commited on
Commit
6a125fd
1 Parent(s): 7c204cc

Uploaded colab version of app

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Biome_Classifier_4.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/18IX5V6Qgf-WhhfFRvT9KZZXu5_dCs4pT
8
+ """
9
+
10
+ from google.colab import drive
11
+ drive.mount('/content/drive')
12
+
13
+ # Commented out IPython magic to ensure Python compatibility.
14
+ # #hide
15
+ # %%capture
16
+ # ! [ -e /content ] && pip install -Uqq fastbook
17
+ # ! pip install gradio==3.50
18
+ # ! pip install nbdev
19
+ #
20
+ # import fastbook
21
+ # fastbook.setup_book
22
+
23
+ #hide
24
+ from fastbook import *
25
+ from fastai.vision.widgets import *
26
+ import skimage
27
+
28
+ gpath = '/content/drive/MyDrive/'
29
+ learn = load_learner(gpath +'/BiomeClassifierModel.pkl')
30
+
31
+ labels = learn.dls.vocab
32
+
33
+ def predict(img):
34
+ img = PILImage.create(img)
35
+ pred,pred_idx,probs = learn.predict(img)
36
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
37
+
38
+ import gradio as gr
39
+ title = "Biome Classifier"
40
+ description = "World's first biome classifier powered by Artificial Intelligence<br>This neural network analyzes any nature photo and identifies what type of biome it depicts<br>Feel free to upload your own photo or try some examples below<br>Written by David Willis"
41
+ article="<p style='text-align: center'><a href='www.linkedin.com/in/david-willis-dev' target='_blank'>LinkedIn Profile,/a.</p>"
42
+ examples= [gpath + 'forest.jpeg', gpath + 'aquatic.jpeg', gpath + 'desert.jpg', gpath + 'grassland.jpg', gpath + 'tundra.jpeg']
43
+ interpretation='default'
44
+ enable_queue=True
45
+ gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch(share=True)
46
+