Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,45 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from diffusers import
|
| 4 |
from PIL import Image
|
| 5 |
-
import numpy as np
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
pipe =
|
| 9 |
"runwayml/stable-diffusion-v1-5",
|
| 10 |
-
torch_dtype=torch.float16
|
| 11 |
safety_checker=None
|
| 12 |
)
|
| 13 |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 14 |
|
| 15 |
-
def
|
| 16 |
if image is None:
|
| 17 |
-
return None, "Upload
|
| 18 |
|
| 19 |
-
# Simulate MagicDrive: SD img2img
|
| 20 |
-
torch.manual_seed(seed)
|
| 21 |
result = pipe(
|
| 22 |
-
prompt,
|
| 23 |
image=image,
|
| 24 |
-
strength=
|
| 25 |
-
num_inference_steps=
|
| 26 |
guidance_scale=7.5
|
| 27 |
).images[0]
|
| 28 |
|
| 29 |
-
return result, f"
|
| 30 |
|
| 31 |
-
with gr.Blocks(
|
| 32 |
-
gr.Markdown("#
|
| 33 |
|
| 34 |
with gr.Row():
|
|
|
|
| 35 |
with gr.Column():
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
btn = gr.Button("Generate", variant="primary")
|
| 40 |
-
|
| 41 |
-
output_img = gr.Image(label="Output Street View")
|
| 42 |
-
status = gr.Textbox(label="Status")
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
+
# Simple img2img pipeline (MagicDrive effect)
|
| 7 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 8 |
"runwayml/stable-diffusion-v1-5",
|
| 9 |
+
torch_dtype=torch.float16,
|
| 10 |
safety_checker=None
|
| 11 |
)
|
| 12 |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 13 |
|
| 14 |
+
def generate(image, prompt, strength=0.75, steps=20):
|
| 15 |
if image is None:
|
| 16 |
+
return None, "Upload an image first"
|
| 17 |
|
|
|
|
|
|
|
| 18 |
result = pipe(
|
| 19 |
+
prompt=prompt,
|
| 20 |
image=image,
|
| 21 |
+
strength=strength,
|
| 22 |
+
num_inference_steps=steps,
|
| 23 |
guidance_scale=7.5
|
| 24 |
).images[0]
|
| 25 |
|
| 26 |
+
return result, f"Generated: {steps} steps, strength {strength}"
|
| 27 |
|
| 28 |
+
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("# 🚗 Street View Generator (MagicDrive Style)")
|
| 30 |
|
| 31 |
with gr.Row():
|
| 32 |
+
input_img = gr.Image(label="Input Image")
|
| 33 |
with gr.Column():
|
| 34 |
+
prompt = gr.Textbox("realistic street view, detailed, 4k", label="Prompt")
|
| 35 |
+
strength = gr.Slider(0.5, 0.9, 0.75, label="Strength")
|
| 36 |
+
steps = gr.Slider(15, 50, 20, label="Steps")
|
| 37 |
btn = gr.Button("Generate", variant="primary")
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
output_img = gr.Image(label="Output")
|
| 40 |
+
status = gr.Textbox(label="Status")
|
| 41 |
+
|
| 42 |
+
btn.click(generate, [input_img, prompt, strength, steps], [output_img, status])
|
| 43 |
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
demo.launch()
|