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