devpandey262 commited on
Commit
67dd95e
1 Parent(s): 9aeb24e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import requests
5
+
6
+ inception_net = tf.keras.applications.InceptionV3() # load the model
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 = np.expand_dims(inp, axis=0) # add a batch dimension
14
+ inp = tf.keras.applications.inception_v3.preprocess_input(inp)
15
+ prediction = inception_net.predict(inp).flatten()
16
+ return {labels[i]: float(prediction[i]) for i in range(1000)}
17
+
18
+ image = gr.inputs.Image(shape=(299, 299, 3))
19
+ label = gr.outputs.Label(num_top_classes=3)
20
+
21
+ gr.Interface(fn=classify_image, inputs=image, outputs=label, capture_session=True).launch()