""" Complete workflow test for Science Storyteller Tests the full pipeline: Search -> Analyze -> Script -> Audio """ import asyncio import logging from agents.research_agent import ResearchAgent from agents.analysis_agent import AnalysisAgent from agents.audio_agent import AudioAgent logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) async def test_full_workflow(): """Test complete Science Storyteller workflow""" print("\n" + "="*60) print("šŸŽ¬ SCIENCE STORYTELLER - FULL WORKFLOW TEST") print("="*60 + "\n") topic = "AlphaFold protein structure prediction" print(f"šŸ“š Topic: {topic}\n") # Step 1: Search for papers print("šŸ” STEP 1: Searching for research papers...") research_agent = ResearchAgent() papers = await research_agent.search(topic, max_results=3) if not papers: print("āŒ No papers found!") return False print(f"āœ… Found {len(papers)} papers") best_paper = papers[0] print(f" šŸ“„ Selected: {best_paper.get('title', 'Unknown')[:80]}...") print() # Step 2: Analyze and generate summary print("šŸ¤– STEP 2: Analyzing with Claude AI...") analysis_agent = AnalysisAgent() summary = await analysis_agent.summarize(best_paper) if not summary: print("āŒ Failed to generate summary!") return False print(f"āœ… Summary generated ({len(summary)} chars)") print(f" Preview: {summary[:150]}...") print() # Step 3: Generate podcast script print("šŸ“ STEP 3: Creating podcast script...") script = await analysis_agent.create_script(summary, best_paper) if not script: print("āŒ Failed to generate script!") return False print(f"āœ… Script created ({len(script)} chars)") print(f" Preview: {script[:150]}...") print() # Step 4: Generate audio with Kokoro-82M print("šŸŽ¤ STEP 4: Generating audio with Kokoro-82M...") audio_agent = AudioAgent() # Use a short excerpt for testing (full script would be too long/expensive) test_excerpt = script[:500] + "... And that's just the beginning of this fascinating research." audio_path = await audio_agent.text_to_speech( test_excerpt, f"test_workflow_{int(asyncio.get_event_loop().time())}.wav" ) if not audio_path: print("āŒ Failed to generate audio!") return False print(f"āœ… Audio generated: {audio_path}") # Check file size from pathlib import Path file_size = Path(audio_path).stat().st_size / 1024 # KB print(f" šŸ“¦ File size: {file_size:.2f} KB") print() # Summary print("="*60) print("šŸŽ‰ WORKFLOW COMPLETE - ALL STEPS SUCCESSFUL!") print("="*60) print("\nResults:") print(f" • Papers found: {len(papers)}") print(f" • Summary length: {len(summary)} chars") print(f" • Script length: {len(script)} chars") print(f" • Audio file: {audio_path}") print(f" • Audio size: {file_size:.2f} KB") print("\nāœ… Ready for production deployment!\n") return True if __name__ == "__main__": try: success = asyncio.run(test_full_workflow()) exit(0 if success else 1) except KeyboardInterrupt: print("\n\nāš ļø Test interrupted by user") exit(1) except Exception as e: print(f"\n\nāŒ Test failed with error: {e}") import traceback traceback.print_exc() exit(1)