poojan1202 commited on
Commit
7bf5681
Β·
verified Β·
1 Parent(s): b941c80

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionInstructPix2PixPipeline
3
+ import torch
4
+
5
+ # Load the uploaded model from Hugging Face
6
+ model = StableDiffusionInstructPix2PixPipeline.from_pretrained("poojan1202/image_modification")
7
+ model.to("cuda") # If you have access to GPU
8
+
9
+ # Define the image-to-image function
10
+ def instruct_pix2pix(image, instruction):
11
+ edited_image = model(image=image, prompt=instruction).images[0]
12
+ return edited_image
13
+
14
+ # Create the Gradio interface
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown("# InstructPix2Pix: Image-to-Image Editing")
17
+ with gr.Row():
18
+ with gr.Column():
19
+ image_input = gr.Image(source="upload", type="pil")
20
+ instruction_input = gr.Textbox(label="Instruction", placeholder="Describe the edit you want...")
21
+ submit_button = gr.Button("Generate")
22
+ with gr.Column():
23
+ image_output = gr.Image()
24
+
25
+ submit_button.click(instruct_pix2pix, inputs=[image_input, instruction_input], outputs=image_output)
26
+
27
+ # Launch the app
28
+ demo.launch()