File size: 2,188 Bytes
8f0f112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
# =============================================================================
# BacSense v2 β€” Usage Examples
# pip install -r requirements.txt
# =============================================================================

from inference import BacSense

# ── Basic usage ───────────────────────────────────────────────────
model = BacSense("bacsense_v2_package")
model.warmup()  # pre-load at startup (optional but recommended)

result = model.predict("image.png", verbose=True)
print(result["prediction"])   # Escherichia coli
print(result["confidence"])   # 0.9621
print(result["gram"])         # Negative
print(result["shape"])        # Rod
print(result["risk"])         # High

# ── Batch prediction ──────────────────────────────────────────────
results = model.predict_batch(["img1.png", "img2.png", "img3.png"])
for r in results:
    print(r["prediction"], r["confidence"])

# ── Streamlit app ─────────────────────────────────────────────────
# import streamlit as st
# from inference import BacSense
#
# @st.cache_resource
# def load_model():
#     m = BacSense("bacsense_v2_package")
#     m.warmup()
#     return m
#
# model = load_model()
# st.title("BacSense v2 β€” Bacterial Classifier")
# uploaded = st.file_uploader("Upload microscopy image", type=["png","jpg","jpeg"])
# if uploaded:
#     with open("temp_input.png", "wb") as f:
#         f.write(uploaded.read())
#     result = model.predict("temp_input.png", verbose=True)
#     st.success(f"Prediction: {result['prediction']}")
#     st.metric("Confidence", f"{result['confidence']:.2%}")
#     col1, col2, col3 = st.columns(3)
#     col1.metric("Gram Stain", result["gram"])
#     col2.metric("Shape",      result["shape"])
#     col3.metric("Risk Level", result["risk"])
#     if result["routed_to_specialist"]:
#         st.info("Specialist classifier was used for E.coli / P.aeruginosa disambiguation")