File size: 1,597 Bytes
0872885 5e8618d 0872885 5e8618d 0872885 5e8618d 0872885 5e8618d 0872885 5e8618d f8629cd 0872885 5e8618d 0872885 5e8618d f8629cd 5e8618d f8629cd 5e8618d f8629cd 5e8618d f8629cd 5e8618d 0872885 5e8618d 0872885 5e8618d | 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 52 53 | import gradio as gr
from PIL import Image
from transformers import pipeline
# Fast lightweight captioning model (like flux)
model = pipeline(
"image-to-text",
model="Salesforce/blip-image-captioning-base"
)
def generate(image):
if image is None:
return "Upload an image first.", ""
caption = model(image)[0]["generated_text"]
final_prompt = (
f"Ultra-realistic cinematic prompt. Scene: {caption}. "
f"Generate an image that matches the uploaded photo as accurately as possible. "
f"Preserve identity, skin tone, hairstyle, facial geometry, and lighting. "
f"Use natural color grading, soft shadows, high dynamic range, and sharp details. "
f"No new objects or changes; match the original photo’s composition and depth-of-field. "
f"Render with 8K realism, natural texture, and clean edges."
)
return caption, final_prompt
with gr.Blocks(css="""
body {background: white;}
#copy-btn, #copy-btn2 {padding: 8px 14px; border-radius: 6px; background: black; color: white;}
""") as demo:
gr.Markdown("## Image → Prompt (Flux-Style Clone)")
img = gr.Image(type="pil", label="Upload Image", height=350)
btn = gr.Button("Generate Prompt", variant="primary")
caption_box = gr.Textbox(
label="Base Caption",
lines=3,
show_copy_button=True
)
final_box = gr.Textbox(
label="Final Cinematic Prompt (Flux/Gemini/Nano)",
lines=6,
show_copy_button=True
)
btn.click(generate, inputs=img, outputs=[caption_box, final_box])
demo.launch() |