Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Residential Architecture Assistant - LangGraph Multi-Agent System | |
| A conversational system that helps users with home design, budget analysis, and floorplan planning. | |
| """ | |
| import os | |
| from dotenv import load_dotenv | |
| from graph import ArchitectureAssistant | |
| def print_welcome(): | |
| """Print welcome message""" | |
| print("\nπ Welcome to your Residential Architecture Assistant! π ") | |
| print("=" * 60) | |
| print("I'm here to help you with:") | |
| print("β’ General home design questions and architectural advice") | |
| print("β’ Budget analysis for the Montreal housing market") | |
| print("β’ Floorplan planning and room layout design") | |
| print("\nI'll remember everything we discuss throughout our conversation.") | |
| print("Type 'quit', 'exit', or 'bye' to end our session.") | |
| print("Type 'summary' to see what we've covered so far.") | |
| print("Type 'reset' to start over with a fresh conversation.") | |
| print("=" * 60) | |
| def print_summary(assistant: ArchitectureAssistant): | |
| """Print conversation summary""" | |
| summary = assistant.get_conversation_summary() | |
| print("\nπ CONVERSATION SUMMARY") | |
| print("-" * 30) | |
| # User requirements | |
| reqs = summary["user_requirements"] | |
| print("USER REQUIREMENTS:") | |
| if reqs["budget"]: | |
| print(f" Budget: ${reqs['budget']:,.0f}") | |
| if reqs["location"]: | |
| print(f" Location: {reqs['location']}") | |
| if reqs["family_size"]: | |
| print(f" Family size: {reqs['family_size']}") | |
| if reqs["lifestyle_preferences"]: | |
| print(f" Preferences: {', '.join(reqs['lifestyle_preferences'])}") | |
| # Floorplan requirements | |
| floor_reqs = summary["floorplan_requirements"] | |
| print("\nFLOORPLAN REQUIREMENTS:") | |
| if floor_reqs["num_floors"]: | |
| print(f" Floors: {floor_reqs['num_floors']}") | |
| if floor_reqs["total_sqft"]: | |
| print(f" Total sq ft: {floor_reqs['total_sqft']}") | |
| if floor_reqs["rooms"]: | |
| rooms_str = ", ".join([f"{r['count']}x {r['type']}" for r in floor_reqs["rooms"]]) | |
| print(f" Rooms: {rooms_str}") | |
| print(f"\nCurrent topic: {summary['current_topic'] or 'General conversation'}") | |
| print(f"Total messages: {summary['total_messages']}") | |
| print("-" * 30) | |
| def main(): | |
| """Main conversation loop""" | |
| # Load environment variables | |
| load_dotenv() | |
| # Get API key | |
| api_key = os.getenv("OPENAI_API_KEY") | |
| if not api_key: | |
| print("β Error: Please set your OPENAI_API_KEY in a .env file") | |
| print("Copy .env.example to .env and add your OpenAI API key.") | |
| return | |
| # Initialize assistant | |
| try: | |
| assistant = ArchitectureAssistant(api_key) | |
| print_welcome() | |
| except Exception as e: | |
| print(f"β Error initializing assistant: {e}") | |
| return | |
| # Main conversation loop | |
| while True: | |
| try: | |
| user_input = input("\n㪠You: ").strip() | |
| if not user_input: | |
| continue | |
| # Handle special commands | |
| if user_input.lower() in ['quit', 'exit', 'bye']: | |
| print("\nπ Thanks for using the Architecture Assistant! Good luck with your home design!") | |
| break | |
| elif user_input.lower() == 'summary': | |
| print_summary(assistant) | |
| continue | |
| elif user_input.lower() == 'reset': | |
| assistant.reset_conversation() | |
| print("\nπ Conversation reset! Let's start fresh.") | |
| continue | |
| # Process user input | |
| print("\nπ€ Assistant: ", end="") | |
| response = assistant.chat(user_input) | |
| print(response) | |
| # Check if a floorplan figure was generated | |
| if assistant.state["messages"]: | |
| last_message = assistant.state["messages"][-1] | |
| if last_message.get("figure_path"): | |
| print(f"\nπ Floorplan diagram saved to: {last_message['figure_path']}") | |
| print(" You can open this file to view your custom floorplan!") | |
| except KeyboardInterrupt: | |
| print("\n\nπ Goodbye!") | |
| break | |
| except Exception as e: | |
| print(f"\nβ Error: {e}") | |
| print("Please try again or type 'quit' to exit.") | |
| if __name__ == "__main__": | |
| main() |