File size: 825 Bytes
7df6ff3
 
0f3f723
7df6ff3
0b16ed1
7df6ff3
9d524b4
7df6ff3
0b16ed1
e8585dd
 
9d524b4
7df6ff3
9d524b4
7df6ff3
 
 
 
9d524b4
f70dd47
 
7df6ff3
9d524b4
7df6ff3
9d524b4
 
7df6ff3
9d524b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from huggingface_hub import from_pretrained_keras
import gradio as gr
import tensorflow as tf

model = from_pretrained_keras("araeynn/validation_model")


def image_classifier(inp):
    class_names = ["0", "1"]
    inp.save("why.png")
    sunflower_path = "why.png"
    img = tf.keras.utils.load_img(sunflower_path, target_size=(256, 256))
    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 = {}
    print(score)
    for s in score:
        print(s)
    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)