HeinSight-Demo / app.py
ivoryzhang's picture
Update app.py
ae36ee1 verified
from heinsight import HeinSight, HeinSightConfig
heinsight = HeinSight(vial_model_path="models/best_vessel.pt",
contents_model_path="models/best_content.pt",
config=HeinSightConfig())
import gradio as gr
description = """
[πŸ”— HeinSight](https://gitlab.com/heingroup/heinsight4.0) detects vials and their contents in a single vessel image.
**Instructions:**
- Upload an image of a container (e.g., a HPLC vial or a reactor). Adjust the **Cap Size Ratio** slider if there is a lid on the vial.This ratio helps the detector estimate the relative size of the vial caps.
**Classifications:**
- **🟫 Empty**: No liquid; dry walls above expected fill line.
- **🟧 Residue**: Visible solid deposit or stain above liquid level.
- **πŸŸ₯ Homogeneous**: Clear liquid, optically uniform.
- **πŸŸͺ Heterogeneous**: Cloudy, turbid, or with phase separation.
- **🟦 Solid**: Dispersed solid in liquid or a separate solid phase visible.
"""
# Gradio UI
demo = gr.Interface(
fn=heinsight.image_demo,
inputs=[
gr.Image(type="pil", label="Single Vessel Image"),
gr.Slider(0.0, 1.0, step=0.01, value=0, label="Cap Size Ratio")
],
outputs=[
gr.Image(type="pil", label="Detected Image"),
gr.JSON(label="Detection Info") # or gr.Textbox() if you prefer plain text
],
title="HeinSight",
examples = [
["https://gitlab.com/heingroup/heinsight4.0/-/raw/main/examples/demo.png", 0.3],
],
description=description
)
if __name__ == "__main__":
demo.launch(mcp_server=True)
__mcp__ = {
"entry_point": heinsight.image_demo,
"inputs": ["image", "cap_ratio"],
"description": "HeinSight vial detector using image + cap ratio"
}