Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import requests
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
inception_net = tf.keras.applications.MobileNetV2()
|
6 |
+
|
7 |
+
response = requests.get("https://git.io/JJkYN")
|
8 |
+
labels = response.text.split("\n")
|
9 |
+
|
10 |
+
def classify_image(inp):
|
11 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
12 |
+
inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
|
13 |
+
prediction = inception_net.predict(inp).flatten()
|
14 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
15 |
+
return confidences
|
16 |
+
|
17 |
+
gr.Interface(fn=classify_image, inputs = gr.inputs.Image(shape = (224, 244)), outputs = gr.outputs.Label(num_top_classes=5)).launch()
|