File size: 940 Bytes
e855ac0
 
 
 
7acea8d
2319edf
379b444
c2cfa5a
7acea8d
 
64202ae
7acea8d
 
 
 
 
b3b1218
7acea8d
c62b67e
 
7acea8d
668d6d8
c62b67e
 
7acea8d
668d6d8
7acea8d
 
 
 
b3b1218
7acea8d
 
 
 
 
c62b67e
7acea8d
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
    Coral Reef Health
"""

import gradio as gr
import tensorflow as tf
import glob
import numpy as np 
from PIL import Image

model_path = "models"
model = tf.saved_model.load(model_path)

classes = [ "bleached" ,  "healthy" , ]

def run(image_path):
    img = Image.open(image_path).convert('RGB')
    img = img.resize((300, 300 * img.size[1] // img.size[0]), Image.ANTIALIAS)
    inp_numpy = np.array(img)[None]
    inp = tf.constant(inp_numpy, dtype='float32')
    class_scores = model(inp)[0].numpy()
    print(class_scores)
    state = classes[class_scores.argmax()]
    return state

title = "Coral Health"
description = (
    ""
)

examples = glob.glob("images/*.jpg")

interface = gr.Interface(
    run,
    inputs=[gr.components.Image(type="filepath")],
    outputs="text",
    #outputs=gradio.outputs.Label(num_top_classes=3),
    title=title,
    description=description,
    examples=examples,
)

interface.queue().launch()