import gradio as gr from transformers import pipeline import torch import numpy as np from PIL import Image import io def remove_background(input_image): try: # Initialize the pipeline with trust_remote_code=True segmentor = pipeline( "image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True, device="cpu" ) # Process the image result = segmentor(input_image) return result['output_image'] except Exception as e: raise gr.Error(f"Error processing image: {str(e)}") # Custom theme with valid colors theme = gr.themes.Soft( primary_hue="orange", # Changed from "gold" to "orange" secondary_hue="blue", neutral_hue="gray" ).set( body_background_fill="linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%)", body_text_color="#ffffff", button_primary_background_fill="linear-gradient(45deg, #FFD700, #FFA500)", button_primary_text_color="#000000", border_color_primary="#FFD700" ) # Create Gradio interface with gr.Blocks(theme=theme) as demo: gr.HTML( """
Remove backgrounds instantly using RMBG V1.4 model