-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_complete_functionality.py
More file actions
120 lines (98 loc) · 4.41 KB
/
test_complete_functionality.py
File metadata and controls
120 lines (98 loc) · 4.41 KB
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
#!/usr/bin/env python3
"""
Test script for StoryTeller with Image Generation
Demonstrates the complete functionality: story → script → audio → images
"""
import os
import sys
from pathlib import Path
# Add the src directory to the Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from storyteller.example import convert_story_to_drama_script, build_audio_drama, generate_story_images
def test_complete_storyteller():
"""Test the complete StoryTeller functionality with image generation."""
print("🎭 StoryTeller Complete Test - Audio + Images")
print("=" * 60)
# Test story
test_story = """
Detective Sarah Chen was investigating a mysterious case in the old library.
Books were disappearing from the shelves every night, but the security cameras
showed nothing. "This doesn't make sense," she muttered to herself. Suddenly,
she heard a soft whisper from the shadows: "The books are not lost, Detective.
They have simply chosen to return home." Sarah turned to see an elderly
librarian with twinkling eyes. "Welcome to the secret library," she said,
gesturing to a hidden door behind the shelves.
"""
print("📖 Test Story:")
print(test_story.strip())
print("\n" + "=" * 60)
try:
# Step 1: Generate Images
print("\n🎨 Step 1: Generating Story Images...")
images = generate_story_images(test_story, max_images=4)
if images:
print(f"✅ Generated {len(images)} images:")
for i, image_data in enumerate(images, 1):
print(f" {i}. {image_data['scene_description']}")
print(f" Timing: {image_data['timing']}")
print(f" Image: {image_data['image_filename']}")
else:
print("❌ No images generated")
return False
# Step 2: Convert to Drama Script
print("\n📝 Step 2: Converting Story to Drama Script...")
script = convert_story_to_drama_script(test_story)
if script:
print(f"✅ Generated {len(script)} script lines:")
for i, entry in enumerate(script[:5], 1): # Show first 5 lines
print(f" {i}. {entry['character']}: {entry['line'][:50]}...")
if len(script) > 5:
print(f" ... and {len(script) - 5} more lines")
else:
print("❌ No script generated")
return False
# Step 3: Generate Audio Drama
print("\n🎵 Step 3: Generating Audio Drama...")
success = build_audio_drama(drama_script=script)
if success:
print("✅ Audio drama generated successfully!")
# Check if audio file exists
audio_file = "final_drama.wav"
if os.path.exists(audio_file):
file_size = os.path.getsize(audio_file) / (1024 * 1024) # MB
print(f" Audio file: {audio_file} ({file_size:.2f} MB)")
else:
print("⚠️ Audio file not found")
else:
print("❌ Audio generation failed")
return False
# Summary
print("\n" + "=" * 60)
print("🎉 COMPLETE SUCCESS!")
print(f"✅ Generated {len(images)} story images")
print(f"✅ Generated {len(script)} script lines")
print("✅ Generated complete audio drama")
print("\n📁 Generated Files:")
# List generated files
if os.path.exists("story_images"):
image_files = list(Path("story_images").glob("*.png"))
print(f" Images: {len(image_files)} files in story_images/")
for img_file in image_files:
print(f" - {img_file.name}")
if os.path.exists("final_drama.wav"):
print(" Audio: final_drama.wav")
if os.path.exists("audio_segments"):
audio_files = list(Path("audio_segments").glob("*.wav"))
print(f" Audio segments: {len(audio_files)} files in audio_segments/")
print("\n🚀 Ready for web application!")
print("Run: streamlit run storyteller_webapp.py")
return True
except Exception as e:
print(f"❌ Test failed with error: {e}")
return False
if __name__ == "__main__":
success = test_complete_storyteller()
if success:
print("\n🎭 StoryTeller is working perfectly!")
else:
print("\n❌ StoryTeller test failed. Check your API keys and dependencies.")