Spaces:
Runtime error
Runtime error
initial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionInstructPix2PixPipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load the model
|
| 6 |
+
model_id = "timbrooks/instruct-pix2pix"
|
| 7 |
+
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
|
| 8 |
+
model_id,
|
| 9 |
+
torch_dtype=torch.float16,
|
| 10 |
+
).to("cuda")
|
| 11 |
+
|
| 12 |
+
# Define the function
|
| 13 |
+
def edit_image(image, prompt):
|
| 14 |
+
image = pipe(prompt, image=image, num_inference_steps=20).images[0]
|
| 15 |
+
return image
|
| 16 |
+
|
| 17 |
+
# Create the UI
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=edit_image,
|
| 20 |
+
inputs=[gr.Image(label="Upload Image"), gr.Textbox(label="Instruction")],
|
| 21 |
+
outputs=gr.Image(label="Result"),
|
| 22 |
+
examples=[["input_example.jpg", "Make the sky stormy"]]
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
demo.launch()
|