import gradio as gr from gradio_client import Client, handle_file from PIL import Image hf_client = Client("multimodalart/cosxl") def run_edit(image, prompt): negative_prompt = "blurry, distorted" guidance_scale = 7 steps = 20 image_path = "/tmp/uploaded_image.png" image.save(image_path) # Predict (returns file path) result_path = hf_client.predict( image=handle_file(image_path), prompt=prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, steps=steps, api_name="/run_edit" ) # Load and return result edited_image = Image.open(result_path).convert("RGB") return edited_image interface = gr.Interface( fn=run_edit, inputs=[ gr.Image(label="Upload Image", type="pil"), gr.Textbox(label="Prompt", placeholder="Describe what to edit") ], outputs=gr.Image(label="Edited Image"), title="Image Editor", description="Uses Hugging Face model for real image editing based on prompt." ) interface.api_name = "/run_edit" interface.launch(show_error = True)