Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,22 +3,31 @@ from PIL import Image
|
|
| 3 |
import torch
|
| 4 |
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
|
| 7 |
-
|
| 8 |
torch_dtype=torch.float16,
|
| 9 |
-
safety_checker=None
|
| 10 |
).to("cuda")
|
|
|
|
| 11 |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 12 |
|
| 13 |
-
def
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
gr.Interface(
|
| 18 |
-
fn=
|
| 19 |
-
inputs=[
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
| 3 |
import torch
|
| 4 |
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
| 5 |
|
| 6 |
+
# Load model from HF Hub (your model repo)
|
| 7 |
+
model_id = "yutengz/ip2p-RoboPredict"
|
| 8 |
+
|
| 9 |
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
|
| 10 |
+
model_id,
|
| 11 |
torch_dtype=torch.float16,
|
| 12 |
+
safety_checker=None,
|
| 13 |
).to("cuda")
|
| 14 |
+
|
| 15 |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 16 |
|
| 17 |
+
def predict(image: Image.Image, prompt: str):
|
| 18 |
+
image = image.convert("RGB").resize((256, 256))
|
| 19 |
+
result = pipe(image=image, prompt=prompt).images[0]
|
| 20 |
+
return result
|
| 21 |
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=predict,
|
| 24 |
+
inputs=[
|
| 25 |
+
gr.Image(type="pil", label="Source Image"),
|
| 26 |
+
gr.Textbox(label="Instruction Prompt", placeholder="e.g., stack the blocks"),
|
| 27 |
+
],
|
| 28 |
+
outputs=gr.Image(label="Predicted Image"),
|
| 29 |
+
title="🧠 ip2p-RoboPredict",
|
| 30 |
+
description="A fine-tuned InstructPix2Pix model for robotic action frame prediction."
|
| 31 |
+
)
|
| 32 |
|
| 33 |
+
demo.launch()
|