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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
SIXR Prompt‑to‑Prototype Studio – Gradio starter app
|
| 3 |
+
====================================================
|
| 4 |
+
A lightweight, one‑file scaffold you can push to a **Hugging Face Gradio Space**.
|
| 5 |
+
It collects a creative prompt (plus optional reference image & visual style),
|
| 6 |
+
then returns placeholder outputs for:
|
| 7 |
+
• Loglines (3 variants)
|
| 8 |
+
• Mood board (1 placeholder image + 9 themed text cells)
|
| 9 |
+
• Shot list (6 items)
|
| 10 |
+
• Animatic description (≈4 s)
|
| 11 |
+
• Pitch summary
|
| 12 |
+
• JSON download bundle
|
| 13 |
+
|
| 14 |
+
Swap the stub generators with your real AI calls (OpenAI, Replicate, etc.)
|
| 15 |
+
when you're ready. Works locally via `python app.py` or `gradio app.py`.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
from __future__ import annotations
|
| 19 |
+
|
| 20 |
+
import datetime as _dt
|
| 21 |
+
import json
|
| 22 |
+
import uuid
|
| 23 |
+
from pathlib import Path
|
| 24 |
+
|
| 25 |
+
import gradio as gr
|
| 26 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 27 |
+
|
| 28 |
+
# -----------------------------------------------------------------------------
|
| 29 |
+
# Config
|
| 30 |
+
# -----------------------------------------------------------------------------
|
| 31 |
+
STYLES = [
|
| 32 |
+
"Default",
|
| 33 |
+
"Cyberpunk",
|
| 34 |
+
"Film Noir",
|
| 35 |
+
"Watercolor",
|
| 36 |
+
"Neo‑Deco",
|
| 37 |
+
]
|
| 38 |
+
PLACEHOLDER_COLOR = (24, 24, 32) # dark bluish‑gray bg
|
| 39 |
+
TEXT_COLOR = (220, 220, 230)
|
| 40 |
+
TMP_DIR = Path("/tmp")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# -----------------------------------------------------------------------------
|
| 44 |
+
# Helper functions
|
| 45 |
+
# -----------------------------------------------------------------------------
|
| 46 |
+
|
| 47 |
+
def _make_placeholder_image(text: str = "Moodboard", size: tuple[int, int] = (512, 512)) -> Image.Image: # noqa: E501
|
| 48 |
+
"""Generate a simple placeholder PIL image with centered text."""
|
| 49 |
+
img = Image.new("RGB", size, color=PLACEHOLDER_COLOR)
|
| 50 |
+
draw = ImageDraw.Draw(img)
|
| 51 |
+
try:
|
| 52 |
+
font = ImageFont.truetype("arial.ttf", 32)
|
| 53 |
+
except Exception: # font might be missing in container – fall back
|
| 54 |
+
font = ImageFont.load_default()
|
| 55 |
+
|
| 56 |
+
w, h = draw.textsize(text, font=font)
|
| 57 |
+
draw.text(((size[0] - w) / 2, (size[1] - h) / 2), text, fill=TEXT_COLOR, font=font)
|
| 58 |
+
return img
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _timestamp() -> str:
|
| 62 |
+
"""Return an ISO‑8601 UTC timestamp (second precision)."""
|
| 63 |
+
return _dt.datetime.utcnow().isoformat(timespec="seconds") + "Z"
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# -----------------------------------------------------------------------------
|
| 67 |
+
# Core generator (stub – replace with your own AI calls)
|
| 68 |
+
# -----------------------------------------------------------------------------
|
| 69 |
+
|
| 70 |
+
def generate_prototype(prompt: str, reference_image: Image.Image | None, style: str):
|
| 71 |
+
"""Return all UI outputs plus a path to the JSON bundle file."""
|
| 72 |
+
|
| 73 |
+
prompt = (prompt or "").strip()
|
| 74 |
+
if not prompt:
|
| 75 |
+
raise gr.Error("Please enter a creative prompt first! ☝️")
|
| 76 |
+
|
| 77 |
+
# --- Loglines ------------------------------------------------------------
|
| 78 |
+
loglines = [
|
| 79 |
+
f"{prompt.capitalize()} – through the lens of {style.lower()} (take {i})."
|
| 80 |
+
for i in range(1, 4)
|
| 81 |
+
]
|
| 82 |
+
|
| 83 |
+
# --- Moodboard -----------------------------------------------------------
|
| 84 |
+
moodboard_img = _make_placeholder_image(f"{style} moodboard")
|
| 85 |
+
moodboard_words = [f"{style} motif #{i}" for i in range(1, 10)]
|
| 86 |
+
|
| 87 |
+
# --- Shot list -----------------------------------------------------------
|
| 88 |
+
framings = [
|
| 89 |
+
"Close‑up",
|
| 90 |
+
"Medium shot",
|
| 91 |
+
"Wide shot",
|
| 92 |
+
"Low‑angle",
|
| 93 |
+
"Over‑the‑shoulder",
|
| 94 |
+
"Drone reveal",
|
| 95 |
+
]
|
| 96 |
+
movements = [
|
| 97 |
+
"push‑in",
|
| 98 |
+
"pull‑out",
|
| 99 |
+
"pan‑left",
|
| 100 |
+
"tilt‑up",
|
| 101 |
+
"handheld",
|
| 102 |
+
"steadycam glide",
|
| 103 |
+
]
|
| 104 |
+
shot_list = [f"{framings[i]} with a {movements[i]}" for i in range(len(framings))]
|
| 105 |
+
|
| 106 |
+
# --- Animatic ------------------------------------------------------------
|
| 107 |
+
animatic = (
|
| 108 |
+
"4‑second sequence: stars dissolve into silhouette; camera drifts forward, "
|
| 109 |
+
"title flares in neon before cutting to black."
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
# --- Pitch summary -------------------------------------------------------
|
| 113 |
+
pitch = (
|
| 114 |
+
f"An immersive concept blending {style.lower()} aesthetics with audience agency "
|
| 115 |
+
f"around the theme: ‘{prompt}'."
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
# --- Bundle everything into a JSON dict ---------------------------------
|
| 119 |
+
bundle = {
|
| 120 |
+
"prompt": prompt,
|
| 121 |
+
"style": style,
|
| 122 |
+
"generated_at": _timestamp(),
|
| 123 |
+
"loglines": loglines,
|
| 124 |
+
"moodboard": {
|
| 125 |
+
"words": moodboard_words,
|
| 126 |
+
"image_placeholder": "(placeholder – no image bytes)",
|
| 127 |
+
},
|
| 128 |
+
"shot_list": shot_list,
|
| 129 |
+
"animatic": animatic,
|
| 130 |
+
"pitch_summary": pitch,
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
json_path = TMP_DIR / f"prototype_{uuid.uuid4().hex}.json"
|
| 134 |
+
json_path.write_text(json.dumps(bundle, indent=2), encoding="utf-8")
|
| 135 |
+
|
| 136 |
+
# Return tuple aligned with UI outputs order
|
| 137 |
+
return (
|
| 138 |
+
loglines,
|
| 139 |
+
moodboard_img,
|
| 140 |
+
"\n".join(moodboard_words),
|
| 141 |
+
"\n".join(shot_list),
|
| 142 |
+
animatic,
|
| 143 |
+
pitch,
|
| 144 |
+
str(json_path),
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
# -----------------------------------------------------------------------------
|
| 149 |
+
# Gradio interface definition
|
| 150 |
+
# -----------------------------------------------------------------------------
|
| 151 |
+
|
| 152 |
+
def build_ui() -> gr.Blocks:
|
| 153 |
+
with gr.Blocks(title="SIXR Prompt‑to‑Prototype Studio") as demo:
|
| 154 |
+
gr.Markdown(
|
| 155 |
+
"# 🚀 SIXR Prompt‑to‑Prototype Studio\n"
|
| 156 |
+
"Turn a single prompt into a mini creative package. Swap the placeholder "
|
| 157 |
+
"logic with your ML models when you’re ready."
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
# --------------------------- Inputs ----------------------------------
|
| 161 |
+
with gr.Row():
|
| 162 |
+
prompt_in = gr.Textbox(
|
| 163 |
+
label="Creative prompt",
|
| 164 |
+
placeholder="Describe your immersive idea…",
|
| 165 |
+
lines=3,
|
| 166 |
+
)
|
| 167 |
+
image_in = gr.Image(
|
| 168 |
+
label="Reference image (optional)",
|
| 169 |
+
type="pil",
|
| 170 |
+
image_mode="RGB",
|
| 171 |
+
)
|
| 172 |
+
style_in = gr.Dropdown(STYLES, value=STYLES[0], label="Visual style")
|
| 173 |
+
|
| 174 |
+
generate_btn = gr.Button("Generate prototype", variant="primary")
|
| 175 |
+
|
| 176 |
+
# --------------------------- Outputs ---------------------------------
|
| 177 |
+
with gr.Tabs():
|
| 178 |
+
with gr.Tab("Loglines"):
|
| 179 |
+
loglines_out = gr.JSON(label="Three logline variants")
|
| 180 |
+
with gr.Tab("Moodboard"):
|
| 181 |
+
mood_img_out = gr.Image(label="Moodboard image")
|
| 182 |
+
mood_txt_out = gr.Textbox(label="Moodboard keywords", lines=10)
|
| 183 |
+
with gr.Tab("Shot list"):
|
| 184 |
+
shots_out = gr.Textbox(label="Shot list", lines=8)
|
| 185 |
+
with gr.Tab("Animatic"):
|
| 186 |
+
anim_out = gr.Textbox(label="Animatic description")
|
| 187 |
+
with gr.Tab("Pitch summary"):
|
| 188 |
+
pitch_out = gr.Textbox(label="Pitch summary")
|
| 189 |
+
|
| 190 |
+
json_file_out = gr.File(label="Download JSON bundle", interactive=False)
|
| 191 |
+
|
| 192 |
+
# Callback wiring
|
| 193 |
+
generate_btn.click(
|
| 194 |
+
fn=generate_prototype,
|
| 195 |
+
inputs=[prompt_in, image_in, style_in],
|
| 196 |
+
outputs=[
|
| 197 |
+
loglines_out,
|
| 198 |
+
mood_img_out,
|
| 199 |
+
mood_txt_out,
|
| 200 |
+
shots_out,
|
| 201 |
+
anim_out,
|
| 202 |
+
pitch_out,
|
| 203 |
+
json_file_out,
|
| 204 |
+
],
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
return demo
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
# -----------------------------------------------------------------------------
|
| 211 |
+
# Main entrypoint
|
| 212 |
+
# -----------------------------------------------------------------------------
|
| 213 |
+
if __name__ == "__main__":
|
| 214 |
+
ui = build_ui()
|
| 215 |
+
# In Spaces, host/port are auto‑set; defaults work fine.
|
| 216 |
+
ui.launch()
|