Spaces:
Sleeping
Sleeping
Add application file
Browse files
App.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
import requests
|
| 5 |
+
from keras.applications.inception_v3 import preprocess_input
|
| 6 |
+
|
| 7 |
+
inception_net = tf.keras.applications.InceptionV3()
|
| 8 |
+
|
| 9 |
+
def classify_image(img):
|
| 10 |
+
img_new = img.reshape((-1, 224, 224, 3))
|
| 11 |
+
img = tf.keras.applications.inception_v3.preprocess_input(img_new)
|
| 12 |
+
prediction = model.predict(img).flatten()
|
| 13 |
+
|
| 14 |
+
return {class_names[i]: float(prediction[i]) for i in range(100)}
|
| 15 |
+
|
| 16 |
+
image = gr.inputs.Image()
|
| 17 |
+
gr.Image(source="webcam", streaming=True)
|
| 18 |
+
|
| 19 |
+
label = gr.outputs.Label(num_top_classes= 5)
|
| 20 |
+
|
| 21 |
+
my_project = gr.Interface(fn=classify_image, inputs=gr.Image(shape=(224, 224), source="upload", streaming=True), outputs=label)
|
| 22 |
+
my_project.launch(debug=True, share=True)
|