|
import gradio as gr |
|
from diffusers import StableDiffusionPanoramaPipeline, DDIMScheduler |
|
import torch |
|
|
|
|
|
base_model = "runwayml/stable-diffusion-v1-5" |
|
scheduler = DDIMScheduler.from_pretrained(base_model, subfolder="scheduler") |
|
|
|
|
|
def create_pipeline_with_lora(): |
|
pipeline = StableDiffusionPanoramaPipeline.from_pretrained(base_model, scheduler=scheduler, torch_dtype=torch.float32) |
|
model_id = "RingL/panodiff" |
|
pipeline.load_lora_weights(model_id) |
|
return pipeline.to("cpu") |
|
|
|
pipeline = create_pipeline_with_lora() |
|
|
|
|
|
def generate_image(prompt): |
|
image = pipeline(prompt).images[0] |
|
return image |
|
|
|
|
|
def gradio_app(prompt_choice, custom_prompt): |
|
if prompt_choice == "Custom": |
|
prompt = custom_prompt |
|
else: |
|
prompt = prompt_choice |
|
return generate_image(prompt) |
|
|
|
example_prompts = [ |
|
"nighttime cityscape with a blue luxury car and a yellow sports car driving on a brightly lit street", |
|
"A vibrant metropolitan skyline at dawn, where the first light of day casts a soft glow over towering skyscrapers and bustling streets below. The city's architecture showcases a blend of modern and historic buildings, creating a rich tapestry of styles. The streets are filled with early morning commuters, street vendors setting up their stalls, and the occasional jogger. The sky transitions from deep blue to pink and gold, with the promise of a beautiful day ahead.", |
|
"A futuristic cityscape at dusk, with sleek, high-tech buildings and neon lights illuminating the city. Hovering vehicles zip through the air, and people walk along elevated walkways, enjoying the evening. The streets below are lined with holographic billboards, cafes, and shops, each adding to the lively atmosphere. The sky is a blend of deep purples and oranges, with stars beginning to twinkle as night falls." |
|
] |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Panorama Image Generation with Diffusers") |
|
prompt_choice = gr.Dropdown(label="Select a Prompt", choices=example_prompts + ["Custom"], value="Custom") |
|
custom_prompt = gr.Textbox(label="Enter Custom Prompt", placeholder="Enter your own prompt here...") |
|
generate_button = gr.Button("Generate Image") |
|
output_image = gr.Image(label="Generated Image", image_mode="RGB") |
|
|
|
generate_button.click(fn=gradio_app, inputs=[prompt_choice, custom_prompt], outputs=output_image) |
|
|
|
|
|
demo.launch() |
|
|