Download app.py from Rex4u/6: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/Rex4u/6/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rex4u/6/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rex4u/6/resolve/main/app.py
1.6 kB
| 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() |