File size: 2,448 Bytes
5cd29b0
 
cfca7b8
34df01d
8ba122d
 
5cd29b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import torch
from diffusers import StableDiffusionPipeline, DDIMScheduler
import gradio as gr

pipe = StableDiffusionPipeline.from_pretrained("MVRL/GeoSynth").cuda()
pipe.enable_xformers_memory_efficient_attention()
# scheduler = DDIMScheduler.from_pretrained("stabilityai/stable-diffusion-2-1-base")
# pipe.scheduler = scheduler

def process(prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta):
    generator = torch.manual_seed(seed)
    output_images = pipe(prompt,
                         height=image_resolution,
                         width=image_resolution,
                         num_inference_steps=ddim_steps,
                         guidance_scale=scale,
                         negative_prompt=n_prompt,
                         num_images_per_prompt=num_samples,
                         eta=eta,
                         generator=generator,
                        ).images
    return output_images

block = gr.Blocks().queue()
with block:
    with gr.Row():
        gr.Markdown(
            """
            # GeoSynth: Contextually-Aware High-Resolution Satellite Image Synthesis
            Srikumar Sastry*, Subash Khanal, Aayush Dhakal, Nathan Jacobs (*Corresponding Author)<br>
            """
        )
    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(label="Prompt")
            run_button = gr.Button(value="Run")
            with gr.Accordion("Advanced options", open=True):
                num_samples = gr.Slider(label="Images", minimum=1, maximum=12, value=1, step=1)
                image_resolution = gr.Slider(label="Image Resolution", minimum=256, maximum=768, value=512, step=64)
                ddim_steps = gr.Slider(label="Steps", minimum=1, maximum=100, value=20, step=1)
                scale = gr.Slider(label="Guidance Scale", minimum=0.1, maximum=30.0, value=7.5, step=0.1)
                seed = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, randomize=True)
                eta = gr.Number(label="eta (DDIM)", value=0.0)
                n_prompt = gr.Textbox(label="Negative Prompt",
                                      value='')
        with gr.Column():
            result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery")
    ips = [prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta]
    run_button.click(fn=process, inputs=ips, outputs=[result_gallery])

block.launch()