Spaces:
Sleeping
Sleeping
| # ============================================================================= | |
| # 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") | |