File size: 11,362 Bytes
09f180e
104838a
 
 
 
09f180e
9f6a480
 
104838a
8535e45
104838a
 
8535e45
 
09f180e
a9221ec
104838a
09f180e
943c1dc
 
b011353
 
104838a
c34376d
 
 
 
 
104838a
c34376d
 
 
41db232
a9221ec
09f180e
104838a
 
09f180e
c34376d
104838a
d6a6164
b011353
104838a
41db232
104838a
 
 
41db232
104838a
9f6a480
c34376d
104838a
c34376d
d6a6164
104838a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6a6164
09f180e
943c1dc
fd625e2
09f180e
 
 
a9221ec
 
 
09f180e
 
 
 
8535e45
09f180e
d1e36b5
 
9f6a480
d1e36b5
 
 
 
 
 
 
 
943c1dc
 
104838a
943c1dc
 
 
fd625e2
943c1dc
 
104838a
943c1dc
 
 
fd625e2
943c1dc
104838a
fd625e2
943c1dc
104838a
943c1dc
a9221ec
 
 
 
 
 
 
 
 
b011353
a9221ec
41db232
 
 
 
 
09f180e
 
943c1dc
 
 
 
 
 
 
09f180e
943c1dc
09f180e
b011353
9f6a480
 
104838a
9f6a480
d6a6164
 
 
 
 
 
9f6a480
 
 
41db232
c34376d
 
 
 
104838a
c34376d
9f6a480
 
c34376d
 
 
 
 
d6a6164
c34376d
 
 
 
 
 
d6a6164
c34376d
d6a6164
104838a
d6a6164
 
 
 
 
 
 
41db232
 
104838a
41db232
 
 
 
 
 
 
c34376d
41db232
 
104838a
41db232
 
d6a6164
41db232
d6a6164
41db232
 
c34376d
 
104838a
c34376d
 
 
 
 
 
 
09f180e
d6a6164
 
 
 
 
 
41db232
d6a6164
 
 
 
 
fd625e2
943c1dc
 
d6a6164
 
 
 
 
 
 
 
c34376d
 
d6a6164
 
 
09f180e
8f843bb
09f180e
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

"""
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()

""