File size: 1,105 Bytes
c917d73 7c9fdc3 c917d73 7c9fdc3 c917d73 7135361 c917d73 7135361 7c9fdc3 c917d73 075527f 7c9fdc3 c917d73 075527f 7c9fdc3 c917d73 7135361 075527f c917d73 7135361 a57237e 075527f c917d73 a67f04e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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) |