Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -89,6 +89,27 @@ def generate_pdf(images, explanations, title="AI-Generated Story Scenes"):
|
|
| 89 |
def reset_fields():
|
| 90 |
return "", "", "", "", "", "Fantasy"
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# -------------------- Core Logic --------------------
|
| 94 |
|
|
@@ -97,13 +118,11 @@ def generate_scene(num_scenes, theme, char_count, character_names, dialogue,
|
|
| 97 |
images, summaries, explanations, recreate_mode=False, current_index=0):
|
| 98 |
|
| 99 |
prompt = (
|
| 100 |
-
f"Scene {current_index + 1}
|
| 101 |
-
f"Characters: {character_names}.
|
| 102 |
-
f"Style: {bg_style}."
|
| 103 |
)
|
| 104 |
-
|
| 105 |
if dialogue:
|
| 106 |
-
prompt += f'
|
| 107 |
prompt += f' Please visualize this as a speech bubble above {dialogue_speaker}, like in a cartoon.'
|
| 108 |
|
| 109 |
image = generate_image_from_text(prompt)
|
|
@@ -336,6 +355,7 @@ with gr.Blocks(
|
|
| 336 |
with gr.Row():
|
| 337 |
generate_btn = gr.Button("➕ Generate The Scene", elem_id="generate-btn")
|
| 338 |
ai_coauthor_btn = gr.Button("🤖 Let AI Write This One", elem_id="ai-write-btn")
|
|
|
|
| 339 |
recreate_btn = gr.Button("🔄 Recreate The Scene", elem_id="recreate-btn")
|
| 340 |
reset_btn = gr.Button("\n⏭️ Reset", elem_id="reset-btn")
|
| 341 |
|
|
@@ -376,12 +396,12 @@ with gr.Blocks(
|
|
| 376 |
|
| 377 |
|
| 378 |
recreate_btn.click(
|
| 379 |
-
fn=
|
| 380 |
inputs=[
|
| 381 |
scene_total, theme, char_count, character_names, dialogue,
|
| 382 |
dialogue_speaker, char_styles, char_moods, bg_style,
|
| 383 |
scene_images, scene_summaries, scene_explanations,
|
| 384 |
-
|
| 385 |
],
|
| 386 |
outputs=[
|
| 387 |
image_output, summary_output, explanation_output,
|
|
@@ -390,6 +410,7 @@ with gr.Blocks(
|
|
| 390 |
]
|
| 391 |
)
|
| 392 |
|
|
|
|
| 393 |
|
| 394 |
ai_coauthor_btn.click(
|
| 395 |
fn=ai_write_scene,
|
|
|
|
| 89 |
def reset_fields():
|
| 90 |
return "", "", "", "", "", "Fantasy"
|
| 91 |
|
| 92 |
+
def recreate_scene_handler(
|
| 93 |
+
num_scenes, theme, char_count, character_names, dialogue,
|
| 94 |
+
dialogue_speaker, char_styles, char_moods, bg_style,
|
| 95 |
+
images, summaries, explanations, scene_number_to_recreate):
|
| 96 |
+
|
| 97 |
+
index = int(scene_number_to_recreate) - 1
|
| 98 |
+
if index < 0 or index >= len(images):
|
| 99 |
+
return (
|
| 100 |
+
None, "", "❌ Invalid input. You have not generated Scene {} yet.".format(scene_number_to_recreate),
|
| 101 |
+
images, summaries, explanations,
|
| 102 |
+
f"⚠️ Scene {scene_number_to_recreate} is not available. Generate it first.", gr.update(visible=False)
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
return generate_scene(
|
| 106 |
+
num_scenes, theme, char_count, character_names, dialogue,
|
| 107 |
+
dialogue_speaker, char_styles, char_moods, bg_style,
|
| 108 |
+
images, summaries, explanations,
|
| 109 |
+
recreate_mode=True, current_index=index
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
|
| 114 |
# -------------------- Core Logic --------------------
|
| 115 |
|
|
|
|
| 118 |
images, summaries, explanations, recreate_mode=False, current_index=0):
|
| 119 |
|
| 120 |
prompt = (
|
| 121 |
+
f"A {bg_style}-style illustration for Scene {current_index + 1} with {char_count} characters in a '{theme}' setting. "
|
| 122 |
+
f"Characters: {character_names}. They are dressed as: {char_styles}. Current mood: {char_moods}. "
|
|
|
|
| 123 |
)
|
|
|
|
| 124 |
if dialogue:
|
| 125 |
+
prompt += f'The character "{dialogue_speaker}" says: "{dialogue}". Display this in a speech bubble.'
|
| 126 |
prompt += f' Please visualize this as a speech bubble above {dialogue_speaker}, like in a cartoon.'
|
| 127 |
|
| 128 |
image = generate_image_from_text(prompt)
|
|
|
|
| 355 |
with gr.Row():
|
| 356 |
generate_btn = gr.Button("➕ Generate The Scene", elem_id="generate-btn")
|
| 357 |
ai_coauthor_btn = gr.Button("🤖 Let AI Write This One", elem_id="ai-write-btn")
|
| 358 |
+
recreate_scene_index = gr.Number(label="🔢 Scene Number to Recreate", precision=0, value=1)
|
| 359 |
recreate_btn = gr.Button("🔄 Recreate The Scene", elem_id="recreate-btn")
|
| 360 |
reset_btn = gr.Button("\n⏭️ Reset", elem_id="reset-btn")
|
| 361 |
|
|
|
|
| 396 |
|
| 397 |
|
| 398 |
recreate_btn.click(
|
| 399 |
+
fn=recreate_scene_handler,
|
| 400 |
inputs=[
|
| 401 |
scene_total, theme, char_count, character_names, dialogue,
|
| 402 |
dialogue_speaker, char_styles, char_moods, bg_style,
|
| 403 |
scene_images, scene_summaries, scene_explanations,
|
| 404 |
+
recreate_scene_index
|
| 405 |
],
|
| 406 |
outputs=[
|
| 407 |
image_output, summary_output, explanation_output,
|
|
|
|
| 410 |
]
|
| 411 |
)
|
| 412 |
|
| 413 |
+
|
| 414 |
|
| 415 |
ai_coauthor_btn.click(
|
| 416 |
fn=ai_write_scene,
|