yutengz commited on
Commit
b1b9f09
·
verified ·
1 Parent(s): a6daf8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
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
- "yutengz/ip2p-RoboPredict",
8
  torch_dtype=torch.float16,
9
- safety_checker=None
10
  ).to("cuda")
 
11
  pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
12
 
13
- def generate(prompt, input_image):
14
- edited = pipe(prompt=prompt, image=input_image.convert("RGB").resize((256, 256))).images[0]
15
- return edited
 
16
 
17
- gr.Interface(
18
- fn=generate,
19
- inputs=[gr.Text(label="Instruction Prompt"), gr.Image(label="Input Image")],
20
- outputs=gr.Image(label="Edited Image"),
21
- title="InstructPix2Pix Finetuned Model",
22
- description="Upload an image and enter an instruction to see how the model transforms it."
23
- ).launch()
 
 
 
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()