chaninder commited on
Commit
d44854d
1 Parent(s): 9206efd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -34
app.py CHANGED
@@ -1,56 +1,26 @@
1
- """
2
- import tensorflow as tf
3
-
4
- inception_net = tf.keras.applications.MobileNetV2()
5
-
6
- import requests
7
-
8
- # Download human-readable labels for ImageNet.
9
- response = requests.get("https://git.io/JJkYN")
10
- labels = response.text.split("\n")
11
-
12
- def classify_image(inp):
13
- inp = inp.reshape((-1, 224, 224, 3))
14
- inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
15
- prediction = inception_net.predict(inp).flatten()
16
- confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
17
- return confidences
18
-
19
- gr.Interface(fn=classify_image,
20
- inputs=gr.Image(shape=(224, 224)),
21
- outputs=gr.Label(num_top_classes=3),
22
- #examples=["banana.jpg", "car.jpg"]
23
- ).launch(share=True)
24
- """
25
-
26
  import gradio as gr
27
  import tensorflow as tf
28
  from tensorflow import keras
29
- import requests
30
 
31
 
32
  # load pre-trained model
33
  model_path = "/Users/chaninderrishi/Desktop/ML/projects/waste-sorting/models/prod3"
34
  pre_trained_model = keras.models.load_model(model_path)
35
 
 
36
  labels = ['compost', 'e-waste', 'recycle', 'trash']
37
 
 
38
  def classify_image(input):
39
  prediction = pre_trained_model.predict(input)
40
  confidences = {labels[i]: float(prediction[i]) for i in range(4)}
41
  return confidences
42
 
43
-
44
  iface = gr.Interface(fn=classify_image,
45
  inputs=gr.Image(shape=(224, 224)),
46
  outputs=gr.Label(num_top_classes=3),
47
  #examples=["banana.jpg", "car.jpg"]
48
  )
49
 
50
- iface.launch(share=True)
51
- """
52
- def greet(name):
53
- return "Hello " + name + "!!"
54
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
55
- iface.launch()
56
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  from tensorflow import keras
 
4
 
5
 
6
  # load pre-trained model
7
  model_path = "/Users/chaninderrishi/Desktop/ML/projects/waste-sorting/models/prod3"
8
  pre_trained_model = keras.models.load_model(model_path)
9
 
10
+ # classification labels
11
  labels = ['compost', 'e-waste', 'recycle', 'trash']
12
 
13
+
14
  def classify_image(input):
15
  prediction = pre_trained_model.predict(input)
16
  confidences = {labels[i]: float(prediction[i]) for i in range(4)}
17
  return confidences
18
 
19
+ # create Gradio interface
20
  iface = gr.Interface(fn=classify_image,
21
  inputs=gr.Image(shape=(224, 224)),
22
  outputs=gr.Label(num_top_classes=3),
23
  #examples=["banana.jpg", "car.jpg"]
24
  )
25
 
26
+ iface.launch(share=True)