-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
46 lines (35 loc) · 1.5 KB
/
app.py
File metadata and controls
46 lines (35 loc) · 1.5 KB
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
import os, sys
# add current directory to top of Python interpreter's module search path
# sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
import streamlit as st
from PIL import Image, ImageOps
from clouds.serving.model_service import CloudClassifier
st.set_page_config(page_title="Atmoscope", page_icon="☁️", layout="centered") # emoji in code spotted!
st.title("Atmoscope: cloud genus classifier")
st.text("Better models are still in progress! ")
st.text("Associated outputs and predictions will display for uploaded photos. ")
st.text("Classifications are multi-label, so multiple cloud types within an image can be identified.")
MODEL_PATH = os.getenv("CLOUDS_MODEL_PATH", "models/clouds_bundle.pt")
@st.cache_resource
def load_service():
return CloudClassifier(MODEL_PATH, device=None)
svc = load_service()
uploaded = st.file_uploader("Upload a cloud photo below.", type=["png", "jpg", "jpeg"])
if uploaded:
img = Image.open(uploaded)
img = ImageOps.exif_transpose(img).convert("RGB") # type: ignore
st.image(img)
probs, preds = svc.predict(img)
TOPK = min(7, len(svc.classes))
rows = sorted(zip(svc.classes, probs, preds), key=lambda x: x[1], reverse=True)[:TOPK]
st.subheader("Predictions")
st.dataframe(
{
"class": [r[0] for r in rows],
"prob": [round(float(r[1]), 3) for r in rows],
"pred": [bool(r[2]) for r in rows],
},
hide_index=True
)
else:
st.info("Upload an image to get predictions.")