CoolFace
Apppublic

wangzerui/Home_Design_Agent

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
main.py125 linesDownload Raw Back to root
1#!/usr/bin/env python32"""3Residential Architecture Assistant - LangGraph Multi-Agent System4A conversational system that helps users with home design, budget analysis, and floorplan planning.5"""6 7import os8from dotenv import load_dotenv9from graph import ArchitectureAssistant10 11 12def print_welcome():13    """Print welcome message"""14    print("\n๐Ÿ  Welcome to your Residential Architecture Assistant! ๐Ÿ ")15    print("=" * 60)16    print("I'm here to help you with:")17    print("โ€ข General home design questions and architectural advice")18    print("โ€ข Budget analysis for the Montreal housing market")19    print("โ€ข Floorplan planning and room layout design")20    print("\nI'll remember everything we discuss throughout our conversation.")21    print("Type 'quit', 'exit', or 'bye' to end our session.")22    print("Type 'summary' to see what we've covered so far.")23    print("Type 'reset' to start over with a fresh conversation.")24    print("=" * 60)25 26 27def print_summary(assistant: ArchitectureAssistant):28    """Print conversation summary"""29    summary = assistant.get_conversation_summary()30    31    print("\n๐Ÿ“‹ CONVERSATION SUMMARY")32    print("-" * 30)33    34    # User requirements35    reqs = summary["user_requirements"]36    print("USER REQUIREMENTS:")37    if reqs["budget"]:38        print(f"  Budget: ${reqs['budget']:,.0f}")39    if reqs["location"]:40        print(f"  Location: {reqs['location']}")41    if reqs["family_size"]:42        print(f"  Family size: {reqs['family_size']}")43    if reqs["lifestyle_preferences"]:44        print(f"  Preferences: {', '.join(reqs['lifestyle_preferences'])}")45    46    # Floorplan requirements47    floor_reqs = summary["floorplan_requirements"]48    print("\nFLOORPLAN REQUIREMENTS:")49    if floor_reqs["num_floors"]:50        print(f"  Floors: {floor_reqs['num_floors']}")51    if floor_reqs["total_sqft"]:52        print(f"  Total sq ft: {floor_reqs['total_sqft']}")53    if floor_reqs["rooms"]:54        rooms_str = ", ".join([f"{r['count']}x {r['type']}" for r in floor_reqs["rooms"]])55        print(f"  Rooms: {rooms_str}")56    57    print(f"\nCurrent topic: {summary['current_topic'] or 'General conversation'}")58    print(f"Total messages: {summary['total_messages']}")59    print("-" * 30)60 61 62def main():63    """Main conversation loop"""64    # Load environment variables65    load_dotenv()66    67    # Get API key68    api_key = os.getenv("OPENAI_API_KEY")69    if not api_key:70        print("โŒ Error: Please set your OPENAI_API_KEY in a .env file")71        print("Copy .env.example to .env and add your OpenAI API key.")72        return73    74    # Initialize assistant75    try:76        assistant = ArchitectureAssistant(api_key)77        print_welcome()78    except Exception as e:79        print(f"โŒ Error initializing assistant: {e}")80        return81    82    # Main conversation loop83    while True:84        try:85            user_input = input("\n๐Ÿ’ฌ You: ").strip()86            87            if not user_input:88                continue89            90            # Handle special commands91            if user_input.lower() in ['quit', 'exit', 'bye']:92                print("\n๐Ÿ‘‹ Thanks for using the Architecture Assistant! Good luck with your home design!")93                break94            95            elif user_input.lower() == 'summary':96                print_summary(assistant)97                continue98            99            elif user_input.lower() == 'reset':100                assistant.reset_conversation()101                print("\n๐Ÿ”„ Conversation reset! Let's start fresh.")102                continue103            104            # Process user input105            print("\n๐Ÿค– Assistant: ", end="")106            response = assistant.chat(user_input)107            print(response)108            109            # Check if a floorplan figure was generated110            if assistant.state["messages"]:111                last_message = assistant.state["messages"][-1]112                if last_message.get("figure_path"):113                    print(f"\n๐Ÿ“ Floorplan diagram saved to: {last_message['figure_path']}")114                    print("   You can open this file to view your custom floorplan!")115            116        except KeyboardInterrupt:117            print("\n\n๐Ÿ‘‹ Goodbye!")118            break119        except Exception as e:120            print(f"\nโŒ Error: {e}")121            print("Please try again or type 'quit' to exit.")122 123 124if __name__ == "__main__":125    main()