Spaces:
Build error
Build error
Update app.py
Browse files4 unmodified lines56789101115 unmodified lines272829293031323334313536373836 unmodified lines75767774787980814 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 sky masks, boxes, phrases, logits = model.predict(image_pil, text_prompt)
# Ensure masks is converted from tensor to NumPy masks_np = masks[0].cpu().numpy() # Convert the tensor to NumPy array
# Convert the mask to a binary format and create a mask image sky_mask = masks[0].astype(np.uint8) * 255 sky_mask = (masks_np > 0).astype(np.uint8) * 255 # Ensure it's a binary mask # Convert PIL image to numpy array for processing img_np = np.array(image_pil)36 unmodified lines outputs = gr.Image(type="pil", label="Resulting Image")
# Launch Gradio app gr.Interface(fn=process_image, inputs=inputs, outputs=outputs, title="Sky Extraction and Color Matching").launch() gr.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