Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import from_pretrained_keras
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
model = from_pretrained_keras("araeynn/e")
|
| 5 |
+
|
| 6 |
+
def image_classifier(inp):
|
| 7 |
+
inp.save("/why.png")
|
| 8 |
+
sunflower_path = "/why.png"
|
| 9 |
+
img = tf.keras.utils.load_img(
|
| 10 |
+
sunflower_path, target_size=(img_height, img_width)
|
| 11 |
+
)
|
| 12 |
+
img_array = tf.keras.utils.img_to_array(img)
|
| 13 |
+
img_array = tf.expand_dims(img_array, 0) # Create a batch
|
| 14 |
+
|
| 15 |
+
predictions = model.predict(img_array)
|
| 16 |
+
score = tf.nn.softmax(predictions)
|
| 17 |
+
r = {}
|
| 18 |
+
for class_name in class_names:
|
| 19 |
+
r[class_name] = score[0][class_names.index(class_name)]
|
| 20 |
+
return r
|
| 21 |
+
demo = gr.Interface(fn=image_classifier, inputs=gr.Image(type="pil"), outputs="label")
|
| 22 |
+
demo.launch(debug=True)
|