Spaces:
Sleeping
Sleeping
""" | |
ChatGPT 4 was used to set up a structure for this project, but then everything was pretty much rewritten as project evolved. | |
We strongly encourage you to integrate GenAI tools into your work. Doing so can not only jump-start your process and provide solutions when you hit a roadblock, but it also offers a fantastic opportunity to deepen your understanding of AI's potential and expand your creative and technical horizons | |
""" | |
import gradio as gr | |
import utils | |
# Load input fields data from the JSON file | |
input_fields = utils.load_input_fields("input_fields.json") | |
models = input_fields.get("models") | |
# Styles | |
photography_styles = input_fields.get("photography_styles") | |
# Environment | |
weather_conditions = input_fields.get("weather_conditions") | |
time_conditions = input_fields.get("time_conditions") | |
moods_atmospheres = input_fields.get("moods_atmospheres") | |
lighting_types = input_fields.get("lighting_types") | |
# Camera and Composition | |
cameras = input_fields.get("cameras") | |
camera_angles = input_fields.get("camera_angles") | |
shot_types = input_fields.get("shot_types") | |
lens_filters = input_fields.get("lens_filters") | |
# Midjourney Only Parameters | |
aspect_ratio_variations = input_fields.get("aspect_ratio_variations") | |
temperature_variations = input_fields.get("temperature_variations") | |
welcome_text="[Photo Style] of [Subject], set in a [Environment — time, weather, etc.] with a [Mood]. Include [Additional Details]. Emulate a [Specific Camera] with a [Lens Filter] and use [Shot Type]. Compose at [Camera Angle] from [Camera Position] perspective. Use [Lighting Conditions]." | |
container_style = "border: 2px solid black; padding: 2rem; font-size: 16px;" | |
html_formated_text=utils.create_html_string(welcome_text, container_style=container_style) | |
def display_camera_info(camera_type): | |
return utils.display_info(cameras, camera_type) | |
def display_light_info(lighting_type): | |
return utils.display_info(lighting_types, lighting_type) | |
def display_lens_info(lens_filter): | |
return utils.display_info(lens_filters, lens_filter) | |
def display_ar_info(aspect_ratio): | |
return utils.display_info(aspect_ratio_variations, aspect_ratio) | |
def display_temperature_info(temperature): | |
return utils.display_info(temperature_variations, temperature) | |
def display_shot_info(shot_type): | |
return utils.display_info(shot_types, shot_type) | |
def compile_prompt(photo_style, subject, enhanced_prompt, weather, time, mood, details, camera_type, camera_angle, shot_type, lens_filter, lighting, model, aspect_ratio, temperature): | |
resulting_prompt = "" | |
if photo_style and photo_style != "None": | |
resulting_prompt += f"{photo_style} of " | |
if subject and (enhanced_prompt is None or enhanced_prompt == ""): | |
resulting_prompt += f"{subject}, " | |
if enhanced_prompt and enhanced_prompt != "": | |
resulting_prompt += f"{enhanced_prompt}, " | |
if weather != "None" or time != "None": | |
resulting_prompt += "set " | |
if weather and weather != "None": | |
resulting_prompt += f" on a {weather} day " | |
if time and time!= "None": | |
resulting_prompt += f"at {time} " | |
if mood and mood != "None": | |
resulting_prompt += f"with a {mood} mood. " | |
if details and (enhanced_prompt is None or enhanced_prompt == ""): | |
resulting_prompt += f"Include {details}. " | |
if camera_type and camera_type != "None": | |
resulting_prompt += f"Shot on {camera_type} " | |
if lens_filter and lens_filter != "None": | |
resulting_prompt += f"with a {lens_filter} lens filter " | |
if shot_type and shot_type != "None": | |
resulting_prompt += f"and use a {shot_type} shot type. " | |
if camera_angle and camera_angle != "None": | |
resulting_prompt += f"Compose at {camera_angle} " | |
if lighting and lighting != "None": | |
resulting_prompt += f"Use {lighting} lighting conditions " | |
if model == "Midjourney" and aspect_ratio != "None": | |
resulting_prompt += f"{utils.find_filter_by_name(aspect_ratio_variations, aspect_ratio)['param']} " | |
if model == "Midjourney" and temperature != "None": | |
resulting_prompt += f"{utils.find_filter_by_name(temperature_variations, temperature)['param']} " | |
return resulting_prompt | |
with gr.Blocks() as demo: | |
isFrog = gr.State(False) | |
gr.Markdown( | |
""" | |
# Let's combine a prompt for you! | |
> There is so much out there, and you have to go find it. We wanted to bring everything together to make building prompts easier. | |
> | |
> \- *Will, Eclair, and Anastasia* | |
""" | |
) | |
gr.HTML(value=html_formated_text) | |
ui_base_model = gr.Radio(choices=models, value="Default", interactive=True,label="Model", info="Select a model you are building a prompt against. Each model has a custom syntax") | |
gr.Markdown( | |
""" | |
## Subject and Details | |
""" | |
) | |
with gr.Row(): | |
with gr.Column(): | |
ui_subject = gr.Textbox(label="Subject of prompt", placeholder="Type your subject", info="Type the subject of the prompt you are creating") | |
with gr.Column(): | |
ui_details = gr.Textbox(label="Details", placeholder="more details", info="Add more details to the prompt") | |
with gr.Row(): | |
with gr.Column(): | |
enhance_button = gr.Button(value="🪄 Enhance Subject", variant="primary", size="lg") | |
with gr.Column(): | |
pwd_input = gr.Textbox(label="Do you know the magic word?", visible=False) | |
confirm_btn = gr.Button(value="Confirm Pwd", visible=False) | |
enhanced_prompt = gr.TextArea(label="Enhanced Prompt", show_copy_button=True, interactive=True, visible=False, lines=3) | |
enhance_button.click( | |
utils.enhance_pipeline, | |
inputs=[isFrog, ui_subject, ui_details], | |
outputs=[pwd_input, confirm_btn, enhanced_prompt] | |
) | |
confirm_btn.click( | |
utils.authenticate, | |
inputs=[pwd_input, ui_subject, ui_details], | |
outputs=[enhanced_prompt,isFrog, pwd_input, confirm_btn] | |
).then(utils.clearInput, outputs=pwd_input) | |
gr.Markdown( | |
""" | |
## Style Descriptor | |
""" | |
) | |
with gr.Tab("Photography Type"): | |
with gr.Row(): | |
with gr.Column(): | |
ui_photography_style = gr.Dropdown(choices=photography_styles, value="None", interactive=True, allow_custom_value=True, label="Photography Style", info="Select a type of photography or add your own.") | |
gr.Markdown( | |
""" | |
## Parameters | |
""" | |
) | |
with gr.Tab("Environment"): | |
with gr.Row(): | |
gr.Markdown( | |
""" | |
Control the lighting conditions, color, and tone in your photos, based on the specific time and weather. | |
""") | |
with gr.Row(): | |
with gr.Column(): | |
ui_weather = gr.Dropdown(choices=weather_conditions, value="None", interactive=True, allow_custom_value=True, label="Weather") | |
with gr.Column(): | |
ui_time = gr.Dropdown(choices=time_conditions, value="None", interactive=True, allow_custom_value=True, label="Time of Day") | |
with gr.Column(): | |
ui_mood = gr.Dropdown(choices=moods_atmospheres, value="None", interactive=True, allow_custom_value=True, label="Mood/Atmosphere", info="Change the tone of your photos or expressions. Note: it will be more effective also adding these descriptors in your subject.") | |
with gr.Row(): | |
with gr.Column(): | |
ui_lighting = gr.Dropdown(choices=utils.extract_names(lighting_types), value="None", interactive=True, allow_custom_value=True, label="Lighting", info="Indicate how you want your subject or scene’s lighting to be") | |
with gr.Column(): | |
lighting_info = gr.Markdown(visible=False) | |
ui_lighting.change( | |
fn=display_light_info, | |
inputs=ui_lighting, | |
outputs=lighting_info | |
) | |
with gr.Tab("Camera and Composition"): | |
with gr.Row("Camera Selection"): | |
with gr.Column(): | |
gr.Markdown( | |
""" | |
Film Camera: 🎞️ | DSLR Camera: 📸 | Special Effect Camera: ✨📷 | |
""") | |
ui_camera_type = gr.Radio(choices=utils.extract_names(cameras), value="None", interactive=True, label="Camera Specs", info="Emulate what you might see if you took the photo from one of these cameras.") | |
with gr.Column(): | |
camera_info_block = gr.Markdown(visible=False) | |
ui_camera_type.change( | |
fn=display_camera_info, | |
inputs=ui_camera_type, | |
outputs=camera_info_block | |
) | |
with gr.Row("Camera Positioning and Shot Type"): | |
gr.Markdown( | |
""" | |
Frame your photo to be as close or far from your subject or scene as you want. | |
""") | |
with gr.Row(): | |
with gr.Column(): | |
ui_camera_angle = gr.Radio(choices=camera_angles, value="None", interactive=True, label="Camera Angles", info="Select an angle") | |
with gr.Column(): | |
ui_shot_type = gr.Radio(choices=utils.extract_names(shot_types), value="None", interactive=True, label="Shot Type", info="Select zoom type") | |
with gr.Column(): | |
shot_type_info = gr.Markdown(visible=False) | |
ui_shot_type.change( | |
fn=display_shot_info, | |
inputs=ui_shot_type, | |
outputs=shot_type_info | |
) | |
with gr.Row("Lens Filter"): | |
with gr.Column(): | |
ui_lens_filter = gr.Radio(choices=utils.extract_names(lens_filters), value="None", interactive=True, label="Lens Filter", info="Give some slight nuance to the tone of your photographs") | |
with gr.Column(): | |
lens_filter_info = gr.Markdown(visible=False) | |
ui_lens_filter.change( | |
fn=display_lens_info, | |
inputs=ui_lens_filter, | |
outputs=lens_filter_info | |
) | |
with gr.Tab(label="Midjourney Only"): | |
with gr.Row("Aspect Ratio"): | |
with gr.Column(): | |
ui_aspect_ratio = gr.Radio(choices=utils.extract_names(aspect_ratio_variations),value="None", interactive=True, label="Aspect Ratio", info="Select the aspect ratio of your photograph") | |
with gr.Column(): | |
aspect_ratio_info = gr.Markdown(visible=False) | |
ui_aspect_ratio.change( | |
fn=display_ar_info, | |
inputs=ui_aspect_ratio, | |
outputs=aspect_ratio_info | |
) | |
with gr.Row("Aspect Ratio"): | |
with gr.Column(): | |
ui_temperature = gr.Radio(choices=utils.extract_names(temperature_variations), value="None", interactive=True, label="Temperature", info="Indicate how much you want your generated photo to stay true to your prompt. Only select these if you want variation, are concepting, or are open to results that can pleasantly surprise you!") | |
with gr.Column(): | |
temperature_info = gr.Markdown(visible=False) | |
ui_temperature.change( | |
fn=display_temperature_info, | |
inputs=ui_temperature, | |
outputs=temperature_info | |
) | |
with gr.Row(): | |
with gr.Column(scale=1): | |
compile_button = gr.Button(value="Compile Prompt", variant="primary", size="lg") | |
with gr.Column(scale=3): | |
result_prompt=gr.TextArea(label="Compiled Prompt", show_copy_button=True, interactive=True) | |
compile_button.click( | |
compile_prompt, | |
inputs=[ | |
ui_photography_style, | |
ui_subject, | |
enhanced_prompt, | |
ui_weather, | |
ui_time, | |
ui_mood, | |
ui_details, | |
ui_camera_type, | |
ui_camera_angle, | |
ui_shot_type, | |
ui_lens_filter, | |
ui_lighting, | |
ui_base_model, | |
ui_aspect_ratio, | |
ui_temperature | |
], | |
outputs=result_prompt | |
) | |
demo.launch() | |
"" |