import gradio as gr from inference import InferencePipeline from PIL import Image # Initialize pipeline once pipeline = InferencePipeline.init_with_workflow( api_key="6D1aSX47hbXwCXPSbzxD", workspace_name="guitar-a5d64", workflow_id="custom-workflow", ) def infer(frame): # frame is a numpy array from Gradio webcam result = pipeline.predict(frame) if result.get("output_image"): img = Image.fromarray(result["output_image"].numpy_image) return img, result.get("predictions", []) else: return None, [] demo = gr.Interface( fn=infer, inputs=gr.Image(source="webcam", streaming=True), outputs=[gr.Image(), "json"], live=True ) demo.launch()