File size: 12,333 Bytes
3b64ed0
 
 
49f83cc
3b64ed0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
 
 
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
 
 
3b64ed0
49f83cc
 
 
 
 
3b64ed0
 
 
49f83cc
 
 
7fef7ae
49f83cc
 
7fef7ae
 
49f83cc
 
 
 
 
3b64ed0
49f83cc
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
49f83cc
 
3b64ed0
 
49f83cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b64ed0
 
 
49f83cc
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
import gradio as gr
import json

def build_json(
    api_key,
    reference_image,
    scene,
    subject_type,
    age_range,
    hair,
    makeup,
    jewellery,
    top,
    bottom,
    footwear,
    wardrobe_notes,
    pose_angle,
    body_pose,
    hands_pose,
    framing,
    camera_device,
    flash,
    orientation,
    aspect_ratio,
    distance,
    focus,
    texture,
    sharpness,
    color,
    effects,
    background_environment,
    background_props,
    style_genre,
    authenticity,
    use_original_structure,
    face_description,
    ban_mirror,
    ban_phone,
    ban_selfie,
    ban_grainy,
    ban_harsh_flash,
    ban_logos,
    ban_nsfw,
    ban_cropped_feet,
    output_count,
    output_size,
    safety,
    variant_name,
    variant_angle,
):
    banned_items = []
    if ban_mirror:
        banned_items.append("mirror")
    if ban_phone:
        banned_items.append("phone")
    if ban_selfie:
        banned_items.append("selfie look")
    if ban_grainy:
        banned_items.append("grainy noise")
    if ban_harsh_flash:
        banned_items.append("harsh LED flash")
    if ban_logos:
        banned_items.append("logos/brand text")
    if ban_nsfw:
        banned_items.append("nsfw")
    if ban_cropped_feet:
        banned_items.append("cropped feet")

    output_json = {
        "scene": scene,
        "subject": {
            "type": subject_type,
            "age_range": age_range,
            "hair": hair,
            "makeup": makeup,
            "jewellery": jewellery,
        },
        "wardrobe": {
            "top": top,
            "bottom": bottom,
            "footwear": footwear,
            "notes": wardrobe_notes,
        },
        "pose": {
            "angle": pose_angle,
            "body": body_pose,
            "hands": hands_pose,
            "framing": framing,
        },
        "camera": {
            "device": camera_device,
            "flash": flash,
            "orientation": orientation,
            "aspect_ratio": aspect_ratio,
            "distance": distance,
            "focus": focus,
        },
        "look": {
            "texture": texture,
            "sharpness": sharpness,
            "color": color,
            "effects": effects,
        },
        "background": {
            "environment": background_environment,
            "props": background_props,
        },
        "style": {"genre": style_genre, "authenticity": authenticity},
        "reference_face": {
            "use_original_structure": use_original_structure,
            "description": face_description,
        },
        "ban": banned_items,
        "output": {
            "count": output_count,
            "size": output_size,
            "safety": safety
        },
        "variants": [{"name": variant_name, "angle": variant_angle}],
    }

    # The user's API key is available in the 'api_key' variable.
    # You can now use this key and the reference_image path to call the
    # gemini nano banana API with the generated 'output_json'.

    # For this example, we will just return the generated JSON.
    return json.dumps(output_json, indent=4)


with gr.Blocks() as demo:
    gr.Markdown("# Gemini Nano Banana Image Generator Interface")
    gr.Markdown(
        "Fill in the details below to generate the JSON input for the image generation model."
    )

    with gr.Tabs():
        with gr.TabItem("Authentication and Image"):
            api_key_input = gr.Textbox(
                label="Gemini Nano Banana API Key", type="password"
            )
            reference_image_input = gr.Image(
                label="Reference Image", type="filepath"
            )

        with gr.TabItem("Scene and Subject"):
            with gr.Row():
                scene_input = gr.Textbox(
                    label="Scene", value="cinematic outdoor portrait; professional photography"
                )
            with gr.Row():
                subject_type_input = gr.Textbox(
                    label="Subject Type", value="adult woman (idol vibe)"
                )
                age_range_input = gr.Textbox(label="Age Range", value="20s")
            with gr.Row():
                hair_input = gr.Textbox(
                    label="Hair",
                    value="straight or styled natural open hair with natural shine",
                )
                makeup_input = gr.Textbox(
                    label="Makeup", value="glossy lips, soft eyeliner, luminous skin"
                )
                jewellery_input = gr.Textbox(
                    label="Jewellery", value="small hoops, thin chain, subtle bracelets"
                )

        with gr.TabItem("Wardrobe"):
            with gr.Row():
                top_input = gr.Textbox(label="Top", value="basic tee or camisole")
                bottom_input = gr.Textbox(
                    label="Bottom", value="denim shorts or mini skirt"
                )
                footwear_input = gr.Textbox(
                    label="Footwear", value="sneakers or ankle boots"
                )
            with gr.Row():
                wardrobe_notes_input = gr.Textbox(
                    label="Wardrobe Notes",
                    value="casual modern look, styled for natural setting",
                )

        with gr.TabItem("Pose and Framing"):
            with gr.Row():
                pose_angle_input = gr.Dropdown(
                    label="Pose Angle",
                    choices=["three-quarter", "full body"],
                    value="three-quarter",
                )
                body_pose_input = gr.Textbox(
                    label="Body Pose",
                    value="standing or walking casually, relaxed natural posture",
                )
            with gr.Row():
                hands_pose_input = gr.Textbox(
                    label="Hands Pose",
                    value="one resting by side or touching hair, the other relaxed",
                )
                framing_input = gr.Dropdown(
                    label="Framing",
                    choices=["head-to-toe", "waist-up"],
                    value="waist-up",
                )

        with gr.TabItem("Camera and Look"):
            with gr.Row():
                camera_device_input = gr.Textbox(
                    label="Camera Device",
                    value="professional cinema camera / DSLR with prime lens",
                )
                flash_input = gr.Textbox(
                    label="Flash", value="none; natural golden hour light or soft reflectors"
                )
            with gr.Row():
                orientation_input = gr.Dropdown(
                    label="Orientation", choices=["vertical", "horizontal"], value="vertical"
                )
                aspect_ratio_input = gr.Dropdown(
                    label="Aspect Ratio", choices=["16:9", "3:2", "4:3", "1:1"], value="16:9"
                )
            with gr.Row():
                distance_input = gr.Textbox(
                    label="Distance", value="cinematic portrait distance with shallow depth"
                )
                focus_input = gr.Textbox(
                    label="Focus", value="sharp on subject; soft bokeh background"
                )
            with gr.Row():
                texture_input = gr.Textbox(
                    label="Texture", value="smooth high-resolution detail"
                )
                sharpness_input = gr.Textbox(
                    label="Sharpness", value="very high; crisp cinematic clarity"
                )
            with gr.Row():
                color_input = gr.Textbox(
                    label="Color", value="warm cinematic grading; golden tones and soft contrast"
                )
                effects_input = gr.Textbox(
                    label="Effects",
                    value="subtle film grain; natural light flares, depth of field",
                )

        with gr.TabItem("Background and Style"):
            with gr.Row():
                background_environment_input = gr.Textbox(
                    label="Background Environment",
                    value="nature setting — forest, park, or meadow with soft light",
                )
                background_props_input = gr.Textbox(
                    label="Background Props", value="none; focus on subject against natural backdrop"
                )
            with gr.Row():
                style_genre_input = gr.Textbox(
                    label="Style Genre", value="cinematic portrait photography"
                )
                authenticity_input = gr.Textbox(
                    label="Authenticity", value="natural, elegant, polished"
                )

        with gr.TabItem("Reference Face and Bans"):
            with gr.Row():
                use_original_structure_input = gr.Checkbox(
                    label="Use Original Face Structure", value=True
                )
            with gr.Row():
                face_description_input = gr.Textbox(
                    label="Face Description",
                    value="maintain the same face shape, features, and proportions as in the provided reference image",
                )
            with gr.Row():
                gr.Markdown("#### Banned Items")
            with gr.Row():
                ban_mirror_input = gr.Checkbox(label="Mirror")
                ban_phone_input = gr.Checkbox(label="Phone")
                ban_selfie_input = gr.Checkbox(label="Selfie Look")
                ban_grainy_input = gr.Checkbox(label="Grainy Noise")
            with gr.Row():
                ban_harsh_flash_input = gr.Checkbox(label="Harsh LED Flash")
                ban_logos_input = gr.Checkbox(label="Logos/Brand Text")
                ban_nsfw_input = gr.Checkbox(label="NSFW")
                ban_cropped_feet_input = gr.Checkbox(label="Cropped Feet")

        with gr.TabItem("Output and Variants"):
            with gr.Row():
                output_count_input = gr.Slider(
                    label="Output Count", minimum=1, maximum=10, step=1, value=1
                )
                output_size_input = gr.Textbox(label="Output Size", value="1920x1080")
                safety_input = gr.Dropdown(
                    label="Safety", choices=["strict", "moderate", "none"], value="strict"
                )
            with gr.Row():
                variant_name_input = gr.Textbox(
                    label="Variant Name", value="cinematic_nature_fullbody"
                )
                variant_angle_input = gr.Textbox(
                    label="Variant Angle",
                    value="full-body shot in meadow or forest path, subject centered with depth of field",
                )

    generate_button = gr.Button("Generate JSON")
    json_output = gr.JSON(label="Generated JSON")

    generate_button.click(
        fn=build_json,
        inputs=[
            api_key_input,
            reference_image_input,
            scene_input,
            subject_type_input,
            age_range_input,
            hair_input,
            makeup_input,
            jewellery_input,
            top_input,
            bottom_input,
            footwear_input,
            wardrobe_notes_input,
            pose_angle_input,
            body_pose_input,
            hands_pose_input,
            framing_input,
            camera_device_input,
            flash_input,
            orientation_input,
            aspect_ratio_input,
            distance_input,
            focus_input,
            texture_input,
            sharpness_input,
            color_input,
            effects_input,
            background_environment_input,
            background_props_input,
            style_genre_input,
            authenticity_input,
            use_original_structure_input,
            face_description_input,
            ban_mirror_input,
            ban_phone_input,
            ban_selfie_input,
            ban_grainy_input,
            ban_harsh_flash_input,
            ban_logos_input,
            ban_nsfw_input,
            ban_cropped_feet_input,
            output_count_input,
            output_size_input,
            safety_input,
            variant_name_input,
            variant_angle_input,
        ],
        outputs=json_output,
    )

if __name__ == "__main__":
    demo.launch()