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 = "

Maturation Status App for Pacific lamprey

" description = "

Upload an ultrasound image to determine the maturation status of a Pacific lamprey

" article="

App & MLM created by Lea R. Medeiros

Pacific Lamprey Restoration Efforts at CRITFC

Pacific Lamprey Conservation Initiative

" #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("

Upload an ultrasound image (ideally taken in the fall following collection) to the Input area and click the Run button. To upload another image, click the Clear button

") 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("

Example images - just drag and drop into the input area and click the Run button

") 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)