Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,11 +74,16 @@ def text_to_speech(text):
|
|
| 74 |
print("TTS error:", e)
|
| 75 |
return None
|
| 76 |
|
| 77 |
-
def generate_pdf(images, explanations):
|
| 78 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
|
| 79 |
doc = SimpleDocTemplate(tmp.name, pagesize=letter)
|
| 80 |
styles = getSampleStyleSheet()
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
for i, img in enumerate(images):
|
| 84 |
if img:
|
|
@@ -94,6 +99,7 @@ def generate_pdf(images, explanations):
|
|
| 94 |
doc.build(story)
|
| 95 |
return tmp.name
|
| 96 |
|
|
|
|
| 97 |
# -------------------- Core Logic --------------------
|
| 98 |
|
| 99 |
def generate_scene(num_scenes, theme, char_count, character_names, dialogue,
|
|
@@ -127,11 +133,11 @@ def generate_scene(num_scenes, theme, char_count, character_names, dialogue,
|
|
| 127 |
|
| 128 |
return image, summary, explanation, images, summaries, explanations, status, gr.update(visible=done_visible)
|
| 129 |
|
| 130 |
-
def finalize_story(images, explanations):
|
| 131 |
if not images or not explanations:
|
| 132 |
return None, None
|
| 133 |
|
| 134 |
-
pdf = generate_pdf(images, explanations)
|
| 135 |
|
| 136 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".txt", mode="w", encoding="utf-8") as txt:
|
| 137 |
for i, exp in enumerate(explanations):
|
|
@@ -140,6 +146,7 @@ def finalize_story(images, explanations):
|
|
| 140 |
|
| 141 |
return txt_path, pdf
|
| 142 |
|
|
|
|
| 143 |
def ai_write_scene(theme, total_scenes, scene_summaries):
|
| 144 |
try:
|
| 145 |
scene_index = len(scene_summaries) + 1
|
|
@@ -406,9 +413,10 @@ with gr.Blocks(
|
|
| 406 |
|
| 407 |
done_btn.click(
|
| 408 |
fn=finalize_story,
|
| 409 |
-
inputs=[scene_images, scene_explanations],
|
| 410 |
outputs=[txt_file, pdf_file]
|
| 411 |
-
|
|
|
|
| 412 |
|
| 413 |
tts_btn.click(
|
| 414 |
fn=text_to_speech,
|
|
|
|
| 74 |
print("TTS error:", e)
|
| 75 |
return None
|
| 76 |
|
| 77 |
+
def generate_pdf(images, explanations, title="AI-Generated Story Scenes"):
|
| 78 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
|
| 79 |
doc = SimpleDocTemplate(tmp.name, pagesize=letter)
|
| 80 |
styles = getSampleStyleSheet()
|
| 81 |
+
|
| 82 |
+
# Add the title at the top
|
| 83 |
+
story = [
|
| 84 |
+
Paragraph(title, styles["Title"]),
|
| 85 |
+
Spacer(1, 24)
|
| 86 |
+
]
|
| 87 |
|
| 88 |
for i, img in enumerate(images):
|
| 89 |
if img:
|
|
|
|
| 99 |
doc.build(story)
|
| 100 |
return tmp.name
|
| 101 |
|
| 102 |
+
|
| 103 |
# -------------------- Core Logic --------------------
|
| 104 |
|
| 105 |
def generate_scene(num_scenes, theme, char_count, character_names, dialogue,
|
|
|
|
| 133 |
|
| 134 |
return image, summary, explanation, images, summaries, explanations, status, gr.update(visible=done_visible)
|
| 135 |
|
| 136 |
+
def finalize_story(images, explanations, title):
|
| 137 |
if not images or not explanations:
|
| 138 |
return None, None
|
| 139 |
|
| 140 |
+
pdf = generate_pdf(images, explanations, title=title)
|
| 141 |
|
| 142 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".txt", mode="w", encoding="utf-8") as txt:
|
| 143 |
for i, exp in enumerate(explanations):
|
|
|
|
| 146 |
|
| 147 |
return txt_path, pdf
|
| 148 |
|
| 149 |
+
|
| 150 |
def ai_write_scene(theme, total_scenes, scene_summaries):
|
| 151 |
try:
|
| 152 |
scene_index = len(scene_summaries) + 1
|
|
|
|
| 413 |
|
| 414 |
done_btn.click(
|
| 415 |
fn=finalize_story,
|
| 416 |
+
inputs=[scene_images, scene_explanations, theme],
|
| 417 |
outputs=[txt_file, pdf_file]
|
| 418 |
+
)
|
| 419 |
+
|
| 420 |
|
| 421 |
tts_btn.click(
|
| 422 |
fn=text_to_speech,
|