sam2ai commited on
Commit
3b64ed0
·
verified ·
1 Parent(s): 28fc25a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +357 -0
app.py ADDED
@@ -0,0 +1,357 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+
4
+ def build_json(
5
+ api_key,
6
+ reference_image,
7
+ scene,
8
+ subject_type,
9
+ age_range,
10
+ hair,
11
+ makeup,
12
+ jewellery,
13
+ top,
14
+ bottom,
15
+ footwear,
16
+ wardrobe_notes,
17
+ pose_angle,
18
+ body_pose,
19
+ hands_pose,
20
+ framing,
21
+ camera_device,
22
+ flash,
23
+ orientation,
24
+ aspect_ratio,
25
+ distance,
26
+ focus,
27
+ texture,
28
+ sharpness,
29
+ color,
30
+ effects,
31
+ background_environment,
32
+ background_props,
33
+ style_genre,
34
+ authenticity,
35
+ use_original_structure,
36
+ face_description,
37
+ ban_mirror,
38
+ ban_phone,
39
+ ban_selfie,
40
+ ban_grainy,
41
+ ban_harsh_flash,
42
+ ban_logos,
43
+ ban_nsfw,
44
+ ban_cropped_feet,
45
+ output_count,
46
+ output_size,
47
+ safety,
48
+ variant_name,
49
+ variant_angle,
50
+ ):
51
+ banned_items = []
52
+ if ban_mirror:
53
+ banned_items.append("mirror")
54
+ if ban_phone:
55
+ banned_items.append("phone")
56
+ if ban_selfie:
57
+ banned_items.append("selfie look")
58
+ if ban_grainy:
59
+ banned_items.append("grainy noise")
60
+ if ban_harsh_flash:
61
+ banned_items.append("harsh LED flash")
62
+ if ban_logos:
63
+ banned_items.append("logos/brand text")
64
+ if ban_nsfw:
65
+ banned_items.append("nsfw")
66
+ if ban_cropped_feet:
67
+ banned_items.append("cropped feet")
68
+
69
+ output_json = {
70
+ "scene": scene,
71
+ "subject": {
72
+ "type": subject_type,
73
+ "age_range": age_range,
74
+ "hair": hair,
75
+ "makeup": makeup,
76
+ "jewellery": jewellery,
77
+ },
78
+ "wardrobe": {
79
+ "top": top,
80
+ "bottom": bottom,
81
+ "footwear": footwear,
82
+ "notes": wardrobe_notes,
83
+ },
84
+ "pose": {
85
+ "angle": pose_angle,
86
+ "body": body_pose,
87
+ "hands": hands_pose,
88
+ "framing": framing,
89
+ },
90
+ "camera": {
91
+ "device": camera_device,
92
+ "flash": flash,
93
+ "orientation": orientation,
94
+ "aspect_ratio": aspect_ratio,
95
+ "distance": distance,
96
+ "focus": focus,
97
+ },
98
+ "look": {
99
+ "texture": texture,
100
+ "sharpness": sharpness,
101
+ "color": color,
102
+ "effects": effects,
103
+ },
104
+ "background": {
105
+ "environment": background_environment,
106
+ "props": background_props,
107
+ },
108
+ "style": {"genre": style_genre, "authenticity": authenticity},
109
+ "reference_face": {
110
+ "use_original_structure": use_original_structure,
111
+ "description": face_description,
112
+ },
113
+ "ban": banned_items,
114
+ "output": {
115
+ "count": output_count,
116
+ "size": output_size,
117
+ "safety": safety
118
+ },
119
+ "variants": [{"name": variant_name, "angle": variant_angle}],
120
+ }
121
+
122
+ # The user's API key is available in the 'api_key' variable.
123
+ # You can now use this key and the reference_image path to call the
124
+ # gemini nano banana API with the generated 'output_json'.
125
+
126
+ # For this example, we will just return the generated JSON.
127
+ return json.dumps(output_json, indent=4)
128
+
129
+
130
+ with gr.Blocks() as demo:
131
+ gr.Markdown("# Gemini Nano Banana Image Generator Interface")
132
+ gr.Markdown(
133
+ "Fill in the details below to generate the JSON input for the image generation model."
134
+ )
135
+
136
+ with gr.Tabs():
137
+ with gr.TabItem("Authentication and Image"):
138
+ api_key_input = gr.Textbox(
139
+ label="Gemini Nano Banana API Key", type="password"
140
+ )
141
+ reference_image_input = gr.Image(
142
+ label="Reference Image", type="filepath"
143
+ )
144
+
145
+ with gr.TabItem("Scene and Subject"):
146
+ with gr.Row():
147
+ scene_input = gr.Textbox(
148
+ label="Scene", value="cinematic outdoor portrait; professional photography"
149
+ )
150
+ with gr.Row():
151
+ subject_type_input = gr.Textbox(
152
+ label="Subject Type", value="adult woman (idol vibe)"
153
+ )
154
+ age_range_input = gr.Textbox(label="Age Range", value="20s")
155
+ with gr.Row():
156
+ hair_input = gr.Textbox(
157
+ label="Hair",
158
+ value="straight or styled natural open hair with natural shine",
159
+ )
160
+ makeup_input = gr.Textbox(
161
+ label="Makeup", value="glossy lips, soft eyeliner, luminous skin"
162
+ )
163
+ jewellery_input = gr.Textbox(
164
+ label="Jewellery", value="small hoops, thin chain, subtle bracelets"
165
+ )
166
+
167
+ with gr.TabItem("Wardrobe"):
168
+ with gr.Row():
169
+ top_input = gr.Textbox(label="Top", value="basic tee or camisole")
170
+ bottom_input = gr.Textbox(
171
+ label="Bottom", value="denim shorts or mini skirt"
172
+ )
173
+ footwear_input = gr.Textbox(
174
+ label="Footwear", value="sneakers or ankle boots"
175
+ )
176
+ with gr.Row():
177
+ wardrobe_notes_input = gr.Textbox(
178
+ label="Wardrobe Notes",
179
+ value="casual modern look, styled for natural setting",
180
+ )
181
+
182
+ with gr.TabItem("Pose and Framing"):
183
+ with gr.Row():
184
+ pose_angle_input = gr.Dropdown(
185
+ label="Pose Angle",
186
+ choices=["three-quarter", "full body"],
187
+ value="three-quarter",
188
+ )
189
+ body_pose_input = gr.Textbox(
190
+ label="Body Pose",
191
+ value="standing or walking casually, relaxed natural posture",
192
+ )
193
+ with gr.Row():
194
+ hands_pose_input = gr.Textbox(
195
+ label="Hands Pose",
196
+ value="one resting by side or touching hair, the other relaxed",
197
+ )
198
+ framing_input = gr.Dropdown(
199
+ label="Framing",
200
+ choices=["head-to-toe", "waist-up"],
201
+ value="waist-up",
202
+ )
203
+
204
+ with gr.TabItem("Camera and Look"):
205
+ with gr.Row():
206
+ camera_device_input = gr.Textbox(
207
+ label="Camera Device",
208
+ value="professional cinema camera / DSLR with prime lens",
209
+ )
210
+ flash_input = gr.Textbox(
211
+ label="Flash", value="none; natural golden hour light or soft reflectors"
212
+ )
213
+ with gr.Row():
214
+ orientation_input = gr.Dropdown(
215
+ label="Orientation", choices=["vertical", "horizontal"], value="vertical"
216
+ )
217
+ aspect_ratio_input = gr.Dropdown(
218
+ label="Aspect Ratio", choices=["16:9", "3:2", "4:3", "1:1"], value="16:9"
219
+ )
220
+ with gr.Row():
221
+ distance_input = gr.Textbox(
222
+ label="Distance", value="cinematic portrait distance with shallow depth"
223
+ )
224
+ focus_input = gr.Textbox(
225
+ label="Focus", value="sharp on subject; soft bokeh background"
226
+ )
227
+ with gr.Row():
228
+ texture_input = gr.Textbox(
229
+ label="Texture", value="smooth high-resolution detail"
230
+ )
231
+ sharpness_input = gr.Textbox(
232
+ label="Sharpness", value="very high; crisp cinematic clarity"
233
+ )
234
+ with gr.Row():
235
+ color_input = gr.Textbox(
236
+ label="Color", value="warm cinematic grading; golden tones and soft contrast"
237
+ )
238
+ effects_input = gr.Textbox(
239
+ label="Effects",
240
+ value="subtle film grain; natural light flares, depth of field",
241
+ )
242
+
243
+ with gr.TabItem("Background and Style"):
244
+ with gr.Row():
245
+ background_environment_input = gr.Textbox(
246
+ label="Background Environment",
247
+ value="nature setting — forest, park, or meadow with soft light",
248
+ )
249
+ background_props_input = gr.Textbox(
250
+ label="Background Props", value="none; focus on subject against natural backdrop"
251
+ )
252
+ with gr.Row():
253
+ style_genre_input = gr.Textbox(
254
+ label="Style Genre", value="cinematic portrait photography"
255
+ )
256
+ authenticity_input = gr.Textbox(
257
+ label="Authenticity", value="natural, elegant, polished"
258
+ )
259
+
260
+ with gr.TabItem("Reference Face and Bans"):
261
+ with gr.Row():
262
+ use_original_structure_input = gr.Checkbox(
263
+ label="Use Original Face Structure", value=True
264
+ )
265
+ with gr.Row():
266
+ face_description_input = gr.Textbox(
267
+ label="Face Description",
268
+ value="maintain the same face shape, features, and proportions as in the provided reference image",
269
+ )
270
+ with gr.Row():
271
+ gr.Markdown("#### Banned Items")
272
+ with gr.Row():
273
+ ban_mirror_input = gr.Checkbox(label="Mirror")
274
+ ban_phone_input = gr.Checkbox(label="Phone")
275
+ ban_selfie_input = gr.Checkbox(label="Selfie Look")
276
+ ban_grainy_input = gr.Checkbox(label="Grainy Noise")
277
+ with gr.Row():
278
+ ban_harsh_flash_input = gr.Checkbox(label="Harsh LED Flash")
279
+ ban_logos_input = gr.Checkbox(label="Logos/Brand Text")
280
+ ban_nsfw_input = gr.Checkbox(label="NSFW")
281
+ ban_cropped_feet_input = gr.Checkbox(label="Cropped Feet")
282
+
283
+ with gr.TabItem("Output and Variants"):
284
+ with gr.Row():
285
+ output_count_input = gr.Slider(
286
+ label="Output Count", minimum=1, maximum=10, step=1, value=1
287
+ )
288
+ output_size_input = gr.Textbox(label="Output Size", value="1920x1080")
289
+ safety_input = gr.Dropdown(
290
+ label="Safety", choices=["strict", "moderate", "none"], value="strict"
291
+ )
292
+ with gr.Row():
293
+ variant_name_input = gr.Textbox(
294
+ label="Variant Name", value="cinematic_nature_fullbody"
295
+ )
296
+ variant_angle_input = gr.Textbox(
297
+ label="Variant Angle",
298
+ value="full-body shot in meadow or forest path, subject centered with depth of field",
299
+ )
300
+
301
+ generate_button = gr.Button("Generate JSON")
302
+ json_output = gr.JSON(label="Generated JSON")
303
+
304
+ generate_button.click(
305
+ fn=build_json,
306
+ inputs=[
307
+ api_key_input,
308
+ reference_image_input,
309
+ scene_input,
310
+ subject_type_input,
311
+ age_range_input,
312
+ hair_input,
313
+ makeup_input,
314
+ jewellery_input,
315
+ top_input,
316
+ bottom_input,
317
+ footwear_input,
318
+ wardrobe_notes_input,
319
+ pose_angle_input,
320
+ body_pose_input,
321
+ hands_pose_input,
322
+ framing_input,
323
+ camera_device_input,
324
+ flash_input,
325
+ orientation_input,
326
+ aspect_ratio_input,
327
+ distance_input,
328
+ focus_input,
329
+ texture_input,
330
+ sharpness_input,
331
+ color_input,
332
+ effects_input,
333
+ background_environment_input,
334
+ background_props_input,
335
+ style_genre_input,
336
+ authenticity_input,
337
+ use_original_structure_input,
338
+ face_description_input,
339
+ ban_mirror_input,
340
+ ban_phone_input,
341
+ ban_selfie_input,
342
+ ban_grainy_input,
343
+ ban_harsh_flash_input,
344
+ ban_logos_input,
345
+ ban_nsfw_input,
346
+ ban_cropped_feet_input,
347
+ output_count_input,
348
+ output_size_input,
349
+ safety_input,
350
+ variant_name_input,
351
+ variant_angle_input,
352
+ ],
353
+ outputs=json_output,
354
+ )
355
+
356
+ if __name__ == "__main__":
357
+ demo.launch()