Spaces:
Build error
Build error
Update app.py
Browse files4 unmodified lines567891015 unmodified lines26272829303132333436 unmodified lines717273747576774 unmodified linesfrom lang_sam import LangSAMfrom color_matcher import ColorMatcherfrom color_matcher.normalizer import Normalizer# Load the LangSAM modelmodel = LangSAM() # Use the default model or specify custom checkpoint: LangSAM("<model_type>", "<path/to/checkpoint>")15 unmodified linesdef extract_and_color_match_sky(image_pil, reference_image_pil, text_prompt="sky"):# Use LangSAM to predict the mask for the skymasks, boxes, phrases, logits = model.predict(image_pil, text_prompt)# Convert the mask to a binary format and create a mask imagesky_mask = masks[0].astype(np.uint8) * 255# Convert PIL image to numpy array for processingimg_np = np.array(image_pil)36 unmodified linesoutputs = gr.Image(type="pil", label="Resulting Image")# Launch Gradio appgr.Interface(fn=process_image, inputs=inputs, outputs=outputs, title="Sky Extraction and Color Matching").launch()# Run the Gradio Interfaceif __name__ == "__main__":4 unmodified lines56789101115 unmodified lines27282930313233343536373836 unmodified lines757677787980814 unmodified linesfrom lang_sam import LangSAMfrom color_matcher import ColorMatcherfrom color_matcher.normalizer import Normalizerimport torch# Load the LangSAM modelmodel = LangSAM() # Use the default model or specify custom checkpoint: LangSAM("<model_type>", "<path/to/checkpoint>")15 unmodified linesdef extract_and_color_match_sky(image_pil, reference_image_pil, text_prompt="sky"):# Use LangSAM to predict the mask for the skymasks, boxes, phrases, logits = model.predict(image_pil, text_prompt)# Ensure masks is converted from tensor to NumPymasks_np = masks[0].cpu().numpy() # Convert the tensor to NumPy array# Convert the mask to a binary format and create a mask imagesky_mask = (masks_np > 0).astype(np.uint8) * 255 # Ensure it's a binary mask# Convert PIL image to numpy array for processingimg_np = np.array(image_pil)36 unmodified linesoutputs = gr.Image(type="pil", label="Resulting Image")# Launch Gradio appgr.Interface(fn=process_image, inputs=inputs, outputs=outputs, title="Sky Extraction and Color Matching").launch(share=True)# Run the Gradio Interfaceif __name__ == "__main__":
app.py+7-3