File size: 2,794 Bytes
d29fe27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
import gradio as gr
from fastai.vision.all import *

from huggingface_hub import from_pretrained_fastai

learn = from_pretrained_fastai("lmedeirosUI/MatStat_Oct22")

labels = learn.dls.vocab
def predict(img):
    img = PILImage.create(img)
    pred, pred_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

#predict('test.jpg') # test

title = "<p style='text-align: center; font-size: 25px; font-weight: bold'>Maturation Status App for Pacific lamprey</p>"
description = "<p style='text-align: center; font-size: 20px'>Upload an ultrasound image to determine the maturation status of a Pacific lamprey</p>"
article="<p style='text-align: center'>App & MLM created by Lea R. Medeiros</p><p style='text-align: center'><a href='https://critfc.org/fish-and-watersheds/columbia-river-fish-species/lamprey/pacific-lamprey-restoration/' target='_blank'>Pacific Lamprey Restoration Efforts at CRITFC</a></p><p style='text-align: center'><a href='https://www.pacificlamprey.org' target='_blank'>Pacific Lamprey Conservation Initiative</a></p>"

#SexID = gr.Interface(fn=predict, inputs=gr.Image(height=512, width=512), outputs=gr.Label(num_top_classes=2), title=title, description=description, examples=examples, article=article)


with gr.Blocks() as MatStat_Oct22:
    gr.Markdown(title)
    gr.Markdown(description)
    with gr.Row():
        with gr.Column(scale=1):
            with gr.Row():
                gr.Markdown("<p style='text-align: center; font-size: 15px'>Upload an ultrasound image (ideally taken in the fall following collection) to the Input area and click the <span style='font-weight: bold'>Run</span> button. To upload another image, click the <span style='font-weight: bold'>Clear</span> button</p>")
            with gr.Row():
                inp = gr.Image(height = 430, label="Input image")
        with gr.Column(scale=1):
            with gr.Row():
                out = gr.Label(num_top_classes=4, label="Maturation Status Prediction")
            with gr.Row():
                btn1 = gr.Button("Run", variant="primary")
                btn1.click(fn=predict, inputs=inp, outputs=out)
            with gr.Row():
                gr.ClearButton([inp, out], variant="secondary")
            with gr.Row():
                gr.Markdown("<p style='text-align: center'>Example images - just drag and drop into the input area and click the <span style='font-weight: bold'>Run</span> button</p>")
            with gr.Row():
                gr.Image("test.JPG", scale=1, label="Example 1")
                gr.Image("test2.JPG", scale=1, label="Example 2")
    with gr.Row():
        gr.Markdown(article)

MatStat_Oct22.launch(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("IBM Plex Sans"), "Arial", "sans-serif"]), ssr_mode=False)