Spaces:
Sleeping
Sleeping
zhiweili
commited on
Commit
·
2ceb133
1
Parent(s):
32b3396
test image to image
Browse files- app.py +39 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import AutoPipelineForImage2Image, DPMSolverMultistepScheduler
|
4 |
+
|
5 |
+
base_model = "SG161222/RealVisXL_V4.0"
|
6 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
+
|
8 |
+
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
9 |
+
base_model, torch_dtype=torch.float16, use_safetensors=True
|
10 |
+
)
|
11 |
+
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
|
12 |
+
pipeline.to(device)
|
13 |
+
generator = torch.Generator(device).manual_seed(0)
|
14 |
+
|
15 |
+
def image_to_image(input_image, prompt, guidance_scale, num_inference_steps):
|
16 |
+
# Generate the output image
|
17 |
+
output_image = pipeline(
|
18 |
+
generator=generator,
|
19 |
+
prompt=prompt, image=input_image,
|
20 |
+
guidance_scale=guidance_scale, num_inference_steps = num_inference_steps
|
21 |
+
).images[0]
|
22 |
+
|
23 |
+
return output_image
|
24 |
+
|
25 |
+
with gr.Block() as grApp:
|
26 |
+
input_image = gr.Image(label="Input Image")
|
27 |
+
prompt = gr.Textbox(lines=3, label="Prompt")
|
28 |
+
guidance_scale = gr.Slider(minimum=0, maximum=1, default=0.75, label="Guidance Scale")
|
29 |
+
num_inference_steps = gr.Slider(minimum=10, maximum=100, default=25, label="Number of Inference Steps")
|
30 |
+
output_image = gr.Image()
|
31 |
+
generate_btn = gr.Button("Generate Image")
|
32 |
+
generate_btn.click(
|
33 |
+
fn=image_to_image,
|
34 |
+
inputs=[input_image, prompt, guidance_scale, num_inference_steps],
|
35 |
+
outputs=output_image,
|
36 |
+
)
|
37 |
+
|
38 |
+
grApp.launch()
|
39 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
diffusers
|