feat: Adjust supported aspect ratios and add Alfred & Frida examples
Browse files- app.py +10 -6
- examples/rpg_character_alfred.json +63 -0
- examples/rpg_character_frida.json +63 -0
- features.yaml +1 -2
app.py
CHANGED
|
@@ -231,21 +231,25 @@ def refine_with_gemini(prompt):
|
|
| 231 |
except Exception as e:
|
| 232 |
return f"Error refining prompt with Gemini: {e}"
|
| 233 |
|
| 234 |
-
def generate_image_with_gemini(refined_prompt, technical_prompt):
|
| 235 |
if not gemini_active:
|
| 236 |
-
return None, "Gemini API key not found in .env file."
|
| 237 |
|
| 238 |
# Priority: Refined Prompt -> Technical Prompt
|
| 239 |
final_prompt = refined_prompt.strip() if refined_prompt and refined_prompt.strip() else technical_prompt.strip()
|
| 240 |
|
| 241 |
if not final_prompt:
|
| 242 |
-
return None, "No prompt available for generation."
|
| 243 |
|
| 244 |
try:
|
| 245 |
# Using the new SDK's generate_images method
|
| 246 |
response = client.models.generate_images(
|
| 247 |
model='imagen-4.0-generate-001',
|
| 248 |
-
prompt=final_prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
)
|
| 250 |
if response.generated_images:
|
| 251 |
img = Image.open(io.BytesIO(response.generated_images[0].image.image_bytes))
|
|
@@ -257,7 +261,7 @@ def generate_image_with_gemini(refined_prompt, technical_prompt):
|
|
| 257 |
return None, None, "Gemini Image generation did not return any images."
|
| 258 |
except Exception as e:
|
| 259 |
traceback.print_exc()
|
| 260 |
-
return None, f"Image Generation Error: {e}"
|
| 261 |
|
| 262 |
def build_ui():
|
| 263 |
with gr.Blocks(title="RPGPortrait Prompt Builder Pro") as demo:
|
|
@@ -389,7 +393,7 @@ def build_ui():
|
|
| 389 |
# Gemini Image Generation
|
| 390 |
gen_img_btn.click(
|
| 391 |
fn=generate_image_with_gemini,
|
| 392 |
-
inputs=[refined_output, prompt_output],
|
| 393 |
outputs=[image_output, download_img_btn, status_msg]
|
| 394 |
).then(
|
| 395 |
fn=lambda x: gr.update(value=x, visible=True) if x else gr.update(visible=False),
|
|
|
|
| 231 |
except Exception as e:
|
| 232 |
return f"Error refining prompt with Gemini: {e}"
|
| 233 |
|
| 234 |
+
def generate_image_with_gemini(refined_prompt, technical_prompt, aspect_ratio):
|
| 235 |
if not gemini_active:
|
| 236 |
+
return None, None, "Gemini API key not found in .env file."
|
| 237 |
|
| 238 |
# Priority: Refined Prompt -> Technical Prompt
|
| 239 |
final_prompt = refined_prompt.strip() if refined_prompt and refined_prompt.strip() else technical_prompt.strip()
|
| 240 |
|
| 241 |
if not final_prompt:
|
| 242 |
+
return None, None, "No prompt available for generation."
|
| 243 |
|
| 244 |
try:
|
| 245 |
# Using the new SDK's generate_images method
|
| 246 |
response = client.models.generate_images(
|
| 247 |
model='imagen-4.0-generate-001',
|
| 248 |
+
prompt=final_prompt,
|
| 249 |
+
config=types.GenerateImagesConfig(
|
| 250 |
+
aspect_ratio=aspect_ratio,
|
| 251 |
+
output_mime_type='image/png'
|
| 252 |
+
)
|
| 253 |
)
|
| 254 |
if response.generated_images:
|
| 255 |
img = Image.open(io.BytesIO(response.generated_images[0].image.image_bytes))
|
|
|
|
| 261 |
return None, None, "Gemini Image generation did not return any images."
|
| 262 |
except Exception as e:
|
| 263 |
traceback.print_exc()
|
| 264 |
+
return None, None, f"Image Generation Error: {e}"
|
| 265 |
|
| 266 |
def build_ui():
|
| 267 |
with gr.Blocks(title="RPGPortrait Prompt Builder Pro") as demo:
|
|
|
|
| 393 |
# Gemini Image Generation
|
| 394 |
gen_img_btn.click(
|
| 395 |
fn=generate_image_with_gemini,
|
| 396 |
+
inputs=[refined_output, prompt_output, dropdowns[-1]], # The last dropdown is Aspect Ratio
|
| 397 |
outputs=[image_output, download_img_btn, status_msg]
|
| 398 |
).then(
|
| 399 |
fn=lambda x: gr.update(value=x, visible=True) if x else gr.update(visible=False),
|
examples/rpg_character_alfred.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"features": {
|
| 3 |
+
"race": "Human",
|
| 4 |
+
"class": "Fighter",
|
| 5 |
+
"gender": "Male",
|
| 6 |
+
"age": "Elderly",
|
| 7 |
+
"expression": "Joyful",
|
| 8 |
+
"pose": "Action",
|
| 9 |
+
"hair_color": "Grey",
|
| 10 |
+
"hair_style": "Messy",
|
| 11 |
+
"eye_color": "Green",
|
| 12 |
+
"build": "Scrawny",
|
| 13 |
+
"skin_tone": "Dark",
|
| 14 |
+
"distinguishing_feature": "Scars",
|
| 15 |
+
"armor": "Chainmail",
|
| 16 |
+
"weapon": "Katana",
|
| 17 |
+
"accessory": "Feathered Hat",
|
| 18 |
+
"accessory2": "Silk Scarf",
|
| 19 |
+
"material": "Polished",
|
| 20 |
+
"background": "Forest",
|
| 21 |
+
"lighting": "Dramatic Side-lighting",
|
| 22 |
+
"atmosphere": "Foggy",
|
| 23 |
+
"vfx": "Arcane Runes",
|
| 24 |
+
"style": "Realistic Photo",
|
| 25 |
+
"mood": "Heroic",
|
| 26 |
+
"camera": "Dynamic3/4",
|
| 27 |
+
"aspect_ratio": "3:4"
|
| 28 |
+
},
|
| 29 |
+
"randomization": {
|
| 30 |
+
"race": false,
|
| 31 |
+
"class": false,
|
| 32 |
+
"gender": false,
|
| 33 |
+
"age": false,
|
| 34 |
+
"expression": false,
|
| 35 |
+
"pose": false,
|
| 36 |
+
"hair_color": false,
|
| 37 |
+
"hair_style": false,
|
| 38 |
+
"eye_color": false,
|
| 39 |
+
"build": false,
|
| 40 |
+
"skin_tone": false,
|
| 41 |
+
"distinguishing_feature": false,
|
| 42 |
+
"armor": false,
|
| 43 |
+
"weapon": false,
|
| 44 |
+
"accessory": false,
|
| 45 |
+
"accessory2": false,
|
| 46 |
+
"material": false,
|
| 47 |
+
"background": false,
|
| 48 |
+
"lighting": false,
|
| 49 |
+
"atmosphere": false,
|
| 50 |
+
"vfx": false,
|
| 51 |
+
"style": false,
|
| 52 |
+
"mood": false,
|
| 53 |
+
"camera": false,
|
| 54 |
+
"aspect_ratio": false
|
| 55 |
+
},
|
| 56 |
+
"extra_info": {
|
| 57 |
+
"identity": "",
|
| 58 |
+
"appearance": "",
|
| 59 |
+
"equipment": "",
|
| 60 |
+
"environment": "",
|
| 61 |
+
"style": ""
|
| 62 |
+
}
|
| 63 |
+
}
|
examples/rpg_character_frida.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"features": {
|
| 3 |
+
"race": "Human",
|
| 4 |
+
"class": "Rogue",
|
| 5 |
+
"gender": "Female",
|
| 6 |
+
"age": "Young Adult",
|
| 7 |
+
"expression": "Enigmatic",
|
| 8 |
+
"pose": "Ready Stance",
|
| 9 |
+
"hair_color": "Blonde",
|
| 10 |
+
"hair_style": "Ponytail",
|
| 11 |
+
"eye_color": "Green",
|
| 12 |
+
"build": "Athletic",
|
| 13 |
+
"skin_tone": "Pale",
|
| 14 |
+
"distinguishing_feature": "Freckles",
|
| 15 |
+
"armor": "Light Leather Armor",
|
| 16 |
+
"weapon": "Rapier",
|
| 17 |
+
"accessory": "Cloak",
|
| 18 |
+
"accessory2": "Hood",
|
| 19 |
+
"material": "Weathered",
|
| 20 |
+
"background": "City Street",
|
| 21 |
+
"lighting": "Soft Golden Hour",
|
| 22 |
+
"atmosphere": "Rainy",
|
| 23 |
+
"vfx": "None",
|
| 24 |
+
"style": "Realistic Photo",
|
| 25 |
+
"mood": "Heroic",
|
| 26 |
+
"camera": "Dynamic3/4",
|
| 27 |
+
"aspect_ratio": "3:4"
|
| 28 |
+
},
|
| 29 |
+
"randomization": {
|
| 30 |
+
"race": false,
|
| 31 |
+
"class": false,
|
| 32 |
+
"gender": false,
|
| 33 |
+
"age": false,
|
| 34 |
+
"expression": false,
|
| 35 |
+
"pose": false,
|
| 36 |
+
"hair_color": false,
|
| 37 |
+
"hair_style": false,
|
| 38 |
+
"eye_color": false,
|
| 39 |
+
"build": false,
|
| 40 |
+
"skin_tone": false,
|
| 41 |
+
"distinguishing_feature": false,
|
| 42 |
+
"armor": false,
|
| 43 |
+
"weapon": false,
|
| 44 |
+
"accessory": false,
|
| 45 |
+
"accessory2": false,
|
| 46 |
+
"material": false,
|
| 47 |
+
"background": false,
|
| 48 |
+
"lighting": false,
|
| 49 |
+
"atmosphere": false,
|
| 50 |
+
"vfx": false,
|
| 51 |
+
"style": false,
|
| 52 |
+
"mood": false,
|
| 53 |
+
"camera": false,
|
| 54 |
+
"aspect_ratio": false
|
| 55 |
+
},
|
| 56 |
+
"extra_info": {
|
| 57 |
+
"identity": "",
|
| 58 |
+
"appearance": "",
|
| 59 |
+
"equipment": "",
|
| 60 |
+
"environment": "",
|
| 61 |
+
"style": ""
|
| 62 |
+
}
|
| 63 |
+
}
|
features.yaml
CHANGED
|
@@ -206,8 +206,7 @@ technical:
|
|
| 206 |
"16:9": "--ar 16:9"
|
| 207 |
"9:16": "--ar 9:16"
|
| 208 |
"4:3": "--ar 4:3"
|
| 209 |
-
"3:
|
| 210 |
-
"2:3": "--ar 2:3"
|
| 211 |
|
| 212 |
templates:
|
| 213 |
default: "A {mood} {style} portrait of {race} {class}, {gender}, {age}. {build} build, {hair_style} {hair_color} hair, {eye_color} eyes, with {distinguishing_feature}. The character is {expression} while {pose}, {armor}, {weapon}{accessories}. All equipment is {material}. The setting is a {background}, {lighting}, {atmosphere}. {vfx}. {camera}. Highly detailed, 8k resolution. {aspect_ratio}"
|
|
|
|
| 206 |
"16:9": "--ar 16:9"
|
| 207 |
"9:16": "--ar 9:16"
|
| 208 |
"4:3": "--ar 4:3"
|
| 209 |
+
"3:4": "--ar 3:4"
|
|
|
|
| 210 |
|
| 211 |
templates:
|
| 212 |
default: "A {mood} {style} portrait of {race} {class}, {gender}, {age}. {build} build, {hair_style} {hair_color} hair, {eye_color} eyes, with {distinguishing_feature}. The character is {expression} while {pose}, {armor}, {weapon}{accessories}. All equipment is {material}. The setting is a {background}, {lighting}, {atmosphere}. {vfx}. {camera}. Highly detailed, 8k resolution. {aspect_ratio}"
|