Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
model_id = "yutengz/ip2p-RoboPredict"
|
| 7 |
+
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None)
|
| 8 |
+
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 9 |
+
pipe = pipe.to("cuda")
|
| 10 |
+
|
| 11 |
+
def infer(prompt, image):
|
| 12 |
+
image = image.convert("RGB").resize((256, 256))
|
| 13 |
+
result = pipe(prompt=prompt, image=image).images[0]
|
| 14 |
+
return result
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(
|
| 17 |
+
fn=infer,
|
| 18 |
+
inputs=[
|
| 19 |
+
gr.Textbox(label="Instruction Prompt"),
|
| 20 |
+
gr.Image(type="pil", label="Source Image"),
|
| 21 |
+
],
|
| 22 |
+
outputs=gr.Image(label="Predicted Image"),
|
| 23 |
+
title="InstructPix2Pix Fine-Tuned on Robotic Frames",
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|