Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,43 @@
|
|
1 |
import gradio as gr
|
2 |
-
from gradio_imageslider import ImageSlider
|
3 |
-
from loadimg import load_img
|
4 |
-
import spaces
|
5 |
-
from transformers import AutoModelForImageSegmentation
|
6 |
import torch
|
7 |
-
from
|
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 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
chameleon = load_img("chameleon.jpg", output_type="pil")
|
49 |
-
|
50 |
-
url = "https://hips.hearstapps.com/hmg-prod/images/gettyimages-1229892983-square.jpg"
|
51 |
-
tab1 = gr.Interface(
|
52 |
-
fn, inputs=image, outputs=slider1, examples=[chameleon], api_name="image"
|
53 |
-
)
|
54 |
-
|
55 |
-
tab2 = gr.Interface(fn, inputs=text, outputs=slider2, examples=[url], api_name="text")
|
56 |
-
|
57 |
-
|
58 |
-
demo = gr.TabbedInterface(
|
59 |
-
[tab1, tab2], ["image", "text"], title="birefnet for background removal"
|
60 |
-
)
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
import torch
|
3 |
+
from diffusers import StableDiffusionInpaintPipeline
|
4 |
+
|
5 |
+
# Load the Stable Diffusion inpainting model
|
6 |
+
def load_inpainting_model():
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
model = StableDiffusionInpaintPipeline.from_pretrained(
|
9 |
+
"runwayml/stable-diffusion-inpainting",
|
10 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
11 |
+
)
|
12 |
+
model.to(device)
|
13 |
+
return model
|
14 |
+
|
15 |
+
# Function to edit the clothing image based on prompt
|
16 |
+
def edit_clothing_image(prompt, image):
|
17 |
+
# Load the model
|
18 |
+
model = load_inpainting_model()
|
19 |
+
|
20 |
+
# Inpainting to edit the image based on the text prompt
|
21 |
+
edited_image = model(prompt=prompt, image=image).images[0]
|
22 |
+
return edited_image
|
23 |
+
|
24 |
+
# Gradio interface
|
25 |
+
def interface():
|
26 |
+
with gr.Blocks() as ui:
|
27 |
+
gr.Markdown("# Clothing Image Editing with AI")
|
28 |
+
|
29 |
+
with gr.Row():
|
30 |
+
with gr.Column():
|
31 |
+
prompt = gr.Textbox(label="Editing Prompt", placeholder="e.g., change the color of the t-shirt to red")
|
32 |
+
input_image = gr.Image(label="Upload Image", tool="editor", type="pil")
|
33 |
+
output_image = gr.Image(label="Edited Image")
|
34 |
+
|
35 |
+
edit_button = gr.Button("Apply Edit")
|
36 |
+
|
37 |
+
edit_button.click(edit_clothing_image, inputs=[prompt, input_image], outputs=output_image)
|
38 |
+
|
39 |
+
return ui
|
40 |
+
|
41 |
+
# Launch the interface
|
42 |
+
ui = interface()
|
43 |
+
ui.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|