Spaces:
Sleeping
Sleeping
Commit ·
1812e67
1
Parent(s): 691cab6
Initial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
|
| 4 |
+
from huggingface_hub import from_pretrained_fastai
|
| 5 |
+
|
| 6 |
+
learn = from_pretrained_fastai("lmedeirosUI/MatStat")
|
| 7 |
+
|
| 8 |
+
labels = learn.dls.vocab
|
| 9 |
+
def predict(img):
|
| 10 |
+
img = PILImage.create(img)
|
| 11 |
+
pred, pred_idx,probs = learn.predict(img)
|
| 12 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 13 |
+
|
| 14 |
+
#predict('test.jpg') # test
|
| 15 |
+
|
| 16 |
+
title = "<p style='text-align: center; font-size: 25px; font-weight: bold'>Sex ID App for Pacific lamprey</p>"
|
| 17 |
+
description = "<p style='text-align: center; font-size: 20px'>Upload an ultrasound image to determine sex of a Pacific lamprey</p>"
|
| 18 |
+
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>"
|
| 19 |
+
|
| 20 |
+
#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)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
with gr.Blocks() as MatStat:
|
| 24 |
+
gr.Markdown(title)
|
| 25 |
+
gr.Markdown(description)
|
| 26 |
+
with gr.Row():
|
| 27 |
+
with gr.Column(scale=1):
|
| 28 |
+
with gr.Row():
|
| 29 |
+
gr.Markdown("<p style='text-align: center; font-size: 15px'>Upload an ultrasound image (ideally taken in the spring 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>")
|
| 30 |
+
with gr.Row():
|
| 31 |
+
inp = gr.Image(height = 430, label="Input image")
|
| 32 |
+
with gr.Column(scale=1):
|
| 33 |
+
with gr.Row():
|
| 34 |
+
out = gr.Label(num_top_classes=4, label="Maturation Status Prediction")
|
| 35 |
+
with gr.Row():
|
| 36 |
+
btn1 = gr.Button("Run", variant="primary")
|
| 37 |
+
btn1.click(fn=predict, inputs=inp, outputs=out)
|
| 38 |
+
with gr.Row():
|
| 39 |
+
gr.ClearButton([inp, out], variant="secondary")
|
| 40 |
+
with gr.Row():
|
| 41 |
+
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>")
|
| 42 |
+
with gr.Row():
|
| 43 |
+
gr.Image("test.jpg", scale=1, label="Example 1")
|
| 44 |
+
gr.Image("test2.jpg", scale=1, label="Example 2")
|
| 45 |
+
with gr.Row():
|
| 46 |
+
gr.Markdown(article)
|
| 47 |
+
|
| 48 |
+
MatStat.launch(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("IBM Plex Sans"), "Arial", "sans-serif"]), ssr_mode=False)
|