import modal
from overeasy import *
from pydantic import BaseModel
from PIL import Image
app = modal.App() # Initialize modal app
@app.function(image=overeasy_image, gpu="a100") # Run the function remotely on a GPU
def run_overeasy(image: Image.Image):
class PPE(BaseModel):
hardhat: bool
workflow = Workflow([
BoundingBoxSelectAgent(classes=["person"]),
NMSAgent(iou_threshold=0.5, score_threshold=0),
SplitAgent(),
DenseCaptioningAgent(),
InstructorTextAgent(response_model=PPE),
ToClassificationAgent(fn=lambda x: "has ppe" if x.hardhat else "no ppe"),
JoinAgent()
])
results, graph = workflow.execute(image)
return results
@app.local_entrypoint() # Run the function locally
def main():
image_path = "./examples/construction_workers.jpg"
image = Image.open(image_path)
results = run_overeasy.remote(image)
results[0].visualize().save("modal_result.jpg")