Spaces:
Running
Running
| import gradio as gr | |
| from gradio_consilium_roundtable import consilium_roundtable | |
| import json | |
| def simulate_travel_planning(): | |
| """Simulate the travel planning conversation from Turin to Philadelphia""" | |
| # Define avatar images for each agent | |
| avatar_images = { | |
| "User Proxy Agent": "https://upload.wikimedia.org/wikipedia/commons/9/99/Sample_User_Icon.png", | |
| "Floor Manager": "https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/250px-Robot_icon.svg.png", | |
| "Convener": "https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/250px-Robot_icon.svg.png", | |
| "Flight Assistant": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Plane-solid.svg/330px-Plane-solid.svg.png", | |
| "Hotel Assistant": "https://upload.wikimedia.org/wikipedia/commons/thumb/5/59/Noun_Project_house_icon_475319_cc.svg/251px-Noun_Project_house_icon_475319_cc.svg.png", | |
| "Rental Car Assistant": "https://upload.wikimedia.org/wikipedia/commons/7/7e/Car_icon_transparent.png", | |
| "Philadelphia Activities Assistant": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Masks-theater-solid.svg/330px-Masks-theater-solid.svg.png" | |
| } | |
| # Initial state - empty, ready for user message | |
| initial_state = { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [], | |
| "currentSpeaker": None, | |
| "thinking": [], | |
| "showBubbles": [], | |
| "avatarImages": avatar_images | |
| } | |
| states = [ | |
| # 1. User Proxy Agent presents the user's request | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "I need to make plans for my trip from Turin to Philadelphia from December 5 to December 10. It'll just be me."} | |
| ], | |
| "currentSpeaker": None, | |
| "thinking": [], | |
| "showBubbles": ["User Proxy Agent"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 2. Floor Manager coordinates and Convener starts thinking | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "I need to make plans for my trip from Turin to Philadelphia from December 5 to December 10. It'll just be me."}, | |
| {"speaker": "Floor Manager", "text": "π― **FLOOR ACTIVATED** - Travel Planning Session\n\nInitiating specialist coordination for Turin β Philadelphia trip..."} | |
| ], | |
| "currentSpeaker": "Floor Manager", | |
| "thinking": ["Convener"], | |
| "showBubbles": ["User Proxy Agent"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 2. Convener invites all travel specialists | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "I need to make plans for my trip from Turin to Philadelphia from December 5 to December 10. It'll just be me."}, | |
| {"speaker": "Floor Manager", "text": "π― FLOOR ACTIVATED - Travel Planning Session"}, | |
| {"speaker": "Convener", "text": "π **CONVENING TRAVEL SPECIALISTS**\n\nInviting all specialists to join the floor:\nβοΈ Flight Assistant\nπ¨ Hotel Assistant\nπ Rental Car Assistant\nπ Philadelphia Activities Assistant"} | |
| ], | |
| "currentSpeaker": "Convener", | |
| "thinking": ["Flight Assistant", "Hotel Assistant"], | |
| "showBubbles": ["User Proxy Agent", "Floor Manager"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 4. Flight Assistant provides flight options | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "I need to make plans for my trip from Turin to Philadelphia from December 5 to December 10. It'll just be me."}, | |
| {"speaker": "Floor Manager", "text": "π― FLOOR coordinating travel specialists"}, | |
| {"speaker": "Convener", "text": "π All travel specialists invited to the floor"}, | |
| {"speaker": "Flight Assistant", "text": "βοΈ **FLIGHT OPTIONS**\n\nTurin β Philadelphia, December 5:\nβ’ Via Rome: β¬850 (12h 15m)\nβ’ Via Paris: β¬920 (13h 10m)\n\nMultiple options available!"} | |
| ], | |
| "currentSpeaker": "Flight Assistant", | |
| "thinking": ["Hotel Assistant", "Rental Car Assistant"], | |
| "showBubbles": ["User Proxy Agent", "Floor Manager", "Convener"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 5. Hotel Assistant provides accommodation options | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "I need to make plans for my trip from Turin to Philadelphia from December 5 to December 10. It'll just be me."}, | |
| {"speaker": "Flight Assistant", "text": "βοΈ Flight options: β¬850-920, multiple routes"}, | |
| {"speaker": "Hotel Assistant", "text": "π¨ **PHILADELPHIA HOTELS**\n\nDecember 5-10 (5 nights):\nβ’ Center City: $195-280/night\nβ’ Airport area: $140-165/night\n\nGreat options in both areas!"} | |
| ], | |
| "currentSpeaker": "Hotel Assistant", | |
| "thinking": ["Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "showBubbles": ["User Proxy Agent", "Flight Assistant"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 6. Rental Car Assistant provides transportation options | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "I need to make plans for my trip from Turin to Philadelphia from December 5 to December 10. It'll just be me."}, | |
| {"speaker": "Flight Assistant", "text": "βοΈ Flights: β¬850-920, multiple routing options"}, | |
| {"speaker": "Hotel Assistant", "text": "π¨ Hotels: $140-280/night, city center and airport"}, | |
| {"speaker": "Rental Car Assistant", "text": "π **RENTAL CARS**\n\nDecember 5-10 pickup at airport:\nβ’ Economy: $45-52/day\nβ’ Mid-size: $65-68/day\nβ’ Premium: $95/day\n\nAlso excellent public transit available!"} | |
| ], | |
| "currentSpeaker": "Rental Car Assistant", | |
| "thinking": ["Philadelphia Activities Assistant"], | |
| "showBubbles": ["Flight Assistant", "Hotel Assistant"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 7. Philadelphia Activities Assistant completes initial planning | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "Sounds good to me!"}, | |
| {"speaker": "Flight Assistant", "text": "βοΈ Flight options available"}, | |
| {"speaker": "Hotel Assistant", "text": "π¨ Hotel accommodations ready"}, | |
| {"speaker": "Rental Car Assistant", "text": "π Ground transportation sorted"}, | |
| {"speaker": "Philadelphia Activities Assistant", "text": "π **PHILADELPHIA ACTIVITIES**\n\nGreat options for December 5-10:\nβ’ Christmas Village at Love Park\nβ’ Philadelphia Museum of Art\nβ’ Independence Hall & Liberty Bell\nβ’ Reading Terminal Market\nβ’ Amazing cheesesteaks!\n\nPhiladelphia will be wonderful!"} | |
| ], | |
| "currentSpeaker": "Philadelphia Activities Assistant", | |
| "thinking": [], | |
| "showBubbles": ["Flight Assistant", "Hotel Assistant", "Rental Car Assistant"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 8. User decides to book the original plan | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "Flight Assistant", "text": "βοΈ Flight options available (β¬850-920)"}, | |
| {"speaker": "Hotel Assistant", "text": "π¨ Hotel accommodations ready ($140-280/night)"}, | |
| {"speaker": "Rental Car Assistant", "text": "π Ground transportation sorted ($45-95/day)"}, | |
| {"speaker": "Philadelphia Activities Assistant", "text": "π Philadelphia activities planned for December 5-10"}, | |
| {"speaker": "User Proxy Agent", "text": "Perfect! This all looks great. Please go ahead and book the flights, hotel, and rental car for December 5-10. I'm ready to finalize everything!"} | |
| ], | |
| "currentSpeaker": "User Proxy Agent", | |
| "thinking": ["Philadelphia Activities Assistant"], | |
| "showBubbles": ["Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Floor Manager"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 9. Activities Assistant suggests Bocelli concert AFTER user wants to book | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "Perfect! This all looks great. Please go ahead and book the flights, hotel, and rental car for December 5-10. I'm ready to finalize everything!"}, | |
| {"speaker": "Philadelphia Activities Assistant", "text": "πΌ **Wait! Before we book...** I just noticed something incredible!\n\nAndrea Bocelli is performing December 11th at Kimmel Center. Since you're from Italy, this could be a once-in-a-lifetime opportunity! Consider staying one extra day?"} | |
| ], | |
| "currentSpeaker": "Philadelphia Activities Assistant", | |
| "thinking": ["Flight Assistant", "Hotel Assistant", "Rental Car Assistant"], | |
| "showBubbles": ["User Proxy Agent", "Floor Manager"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 10. Other agents hear Bocelli suggestion and adapt their recommendations | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "Perfect! This all looks great. Please go ahead and book the flights, hotel, and rental car for December 5-10. I'm ready to finalize everything!"}, | |
| {"speaker": "Philadelphia Activities Assistant", "text": "πΌ **Bocelli concert December 11th!** Consider extending one day?"}, | |
| {"speaker": "Hotel Assistant", "text": "π¨ **Hearing about Bocelli!** π\nKimmel area hotel available Dec 11th - same $195 rate. Worth extending!"}, | |
| {"speaker": "Flight Assistant", "text": "βοΈ **Concert suggestion noted!** π΅\nMonday Dec 12 flights are β¬100+ cheaper than Sunday! Extend and save money."}, | |
| {"speaker": "Rental Car Assistant", "text": "π **Adapting to concert plan!**\nWeekly rate is better anyway - only +$55 for 2 extra days."} | |
| ], | |
| "currentSpeaker": None, | |
| "thinking": ["User Proxy Agent"], | |
| "showBubbles": ["Floor Manager", "Convener", "Philadelphia Activities Assistant"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 11. User says YES to the enhanced plan | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "Philadelphia Activities Assistant", "text": "πΌ Bocelli concert December 11th! Consider extending?"}, | |
| {"speaker": "Hotel Assistant", "text": "π¨ Hotel extension available, same rate!"}, | |
| {"speaker": "Flight Assistant", "text": "βοΈ Monday flights cheaper - extend and save!"}, | |
| {"speaker": "Rental Car Assistant", "text": "π Weekly rental rate is better anyway!"}, | |
| {"speaker": "User Proxy Agent", "text": "YES! Absolutely! Bocelli from my home country performing in Philadelphia? And I save money on flights? This is perfect - let's extend the trip!"} | |
| ], | |
| "currentSpeaker": "User Proxy Agent", | |
| "thinking": ["Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "showBubbles": ["Floor Manager"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 12. All agents process the enhanced bookings | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "User Proxy Agent", "text": "YES! Absolutely! Bocelli from my home country performing in Philadelphia? And I save money on flights? This is perfect - let's extend the trip!"}, | |
| {"speaker": "Flight Assistant", "text": "βοΈ **Extended flights booked!**\nTRNβPHL Dec 5, return Dec 12\nTotal: β¬780 (saved β¬70!)"}, | |
| {"speaker": "Hotel Assistant", "text": "π¨ **Extended stay confirmed!**\nKimmel Center area, Dec 5-12\n7 nights, $1,365 total"}, | |
| {"speaker": "Rental Car Assistant", "text": "π **Extended rental confirmed!**\nHonda Accord, Dec 5-12\n7 days, $315 total"}, | |
| {"speaker": "Philadelphia Activities Assistant", "text": "πΌ **Bocelli concert booked!**\nDec 11, 8pm, Orchestra section\nConfirmation: KIMMEL-456"} | |
| ], | |
| "currentSpeaker": None, | |
| "thinking": [], | |
| "showBubbles": ["User Proxy Agent"], | |
| "avatarImages": avatar_images | |
| }, | |
| # 13. Final celebration and completion | |
| { | |
| "participants": ["User Proxy Agent", "Floor Manager", "Convener", "Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant"], | |
| "messages": [ | |
| {"speaker": "Flight Assistant", "text": "βοΈ Enhanced flights with savings (β¬780)"}, | |
| {"speaker": "Hotel Assistant", "text": "π¨ Extended stay confirmed ($1,365)"}, | |
| {"speaker": "Rental Car Assistant", "text": "π Extended rental confirmed ($315)"}, | |
| {"speaker": "Philadelphia Activities Assistant", "text": "πΌ Bocelli concert secured!"}, | |
| {"speaker": "Floor Manager", "text": "π― **Trip enhanced through collaboration!**\nOriginal: 5 days, ~$2,100\nNew: 7 days + Bocelli, ~$2,650\nAgent teamwork created amazing value! πΌ"}, | |
| {"speaker": "User Proxy Agent", "text": "This collaborative planning is incredible! You saved me money on flights and gave me Bocelli - thank you all!"} | |
| ], | |
| "currentSpeaker": None, | |
| "thinking": [], | |
| "showBubbles": ["Flight Assistant", "Hotel Assistant", "Rental Car Assistant", "Philadelphia Activities Assistant", "Floor Manager", "User Proxy Agent"], | |
| "avatarImages": avatar_images | |
| } | |
| ] | |
| return initial_state, states | |
| def update_discussion_state(state_index, states): | |
| """Get the next state in the travel planning discussion""" | |
| if state_index >= len(states): | |
| state_index = 0 | |
| return states[state_index], state_index + 1 | |
| # Initialize the travel planning discussion | |
| initial_state, discussion_states = simulate_travel_planning() | |
| with gr.Blocks(title="π£οΈ Open Floor Protocol - Roundtable Demo") as demo: | |
| gr.Markdown(""" | |
| # π£οΈ Open Floor Protocol - Roundtable Demo | |
| **Watch AI travel specialists collaborate and adapt!** This simulates a conversation flow using the Open Floor Protocol: a user requests trip planning from Turin to Philadelphia, and specialist agents not only provide recommendations but **listen to each other** and **dynamically improve** the plan together. | |
| π― **Key Feature:** Notice how the Activities Assistant discovers a special concert opportunity, and ALL other agents immediately adapt their recommendations based on what they heard - creating a better trip that actually saves money! | |
| **Read more about [Open Floor](https://github.com/open-voice-interoperability/openfloor-docs) and the [official Python library](https://github.com/open-voice-interoperability/openfloor-python)** | |
| """) | |
| # State management | |
| state_counter = gr.State(0) | |
| # The roundtable component | |
| roundtable = consilium_roundtable( | |
| label="Shared Conversational Space", | |
| show_label=True, | |
| label_icon="https://avatars.githubusercontent.com/u/46052400?s=48&v=4", | |
| value=initial_state | |
| ) | |
| with gr.Row(): | |
| next_btn = gr.Button("βΆοΈ Next Planning Step", variant="primary") | |
| reset_btn = gr.Button("π Reset Planning Session", variant="secondary") | |
| # Status display | |
| with gr.Row(): | |
| status_display = gr.Markdown("**Status:** π― Travel planning floor ready - awaiting user request") | |
| # Trip details display | |
| with gr.Row(): | |
| trip_info = gr.Markdown(""" | |
| ### π§³ Trip Overview | |
| **Route:** Turin, Italy β Philadelphia, USA | |
| **Dates:** December 5-10, 2024 | |
| **Traveler:** Solo trip | |
| **Specialists:** Flight, Hotel, Car Rental, Activities | |
| """) | |
| gr.Markdown(""" | |
| Avatar Images from Wikimedia: | |
| * User Proxy Agent: https://upload.wikimedia.org/wikipedia/commons/9/99/Sample_User_Icon.png | |
| * Floor Manager: https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/250px-Robot_icon.svg.png | |
| * Convener: https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Robot_icon.svg/250px-Robot_icon.svg.png | |
| * Flight Assistant: https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Plane-solid.svg/330px-Plane-solid.svg.png | |
| * Hotel Assistant: https://upload.wikimedia.org/wikipedia/commons/thumb/5/59/Noun_Project_house_icon_475319_cc.svg/251px-Noun_Project_house_icon_475319_cc.svg.png | |
| * Rental Car Assistant: https://upload.wikimedia.org/wikipedia/commons/7/7e/Car_icon_transparent.png | |
| * Philadelphia Activities Assistant: https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Masks-theater-solid.svg/330px-Masks-theater-solid.svg.png | |
| """) | |
| def next_state(current_counter): | |
| new_state, new_counter = update_discussion_state(current_counter, discussion_states) | |
| # Convert to proper JSON string | |
| json_state = json.dumps(new_state) | |
| # Create status message based on current state | |
| thinking_list = new_state.get("thinking", []) | |
| current_speaker = new_state.get("currentSpeaker") | |
| # Custom status messages for travel planning context | |
| if current_counter == 0: | |
| status = "**Status:** π― Floor Manager activating coordination protocols" | |
| elif current_counter == 1: | |
| status = "**Status:** π Convener inviting specialist agents to the floor" | |
| elif current_counter == 6: | |
| status = "**Status:** π User decides to book original 5-day plan..." | |
| elif current_counter == 7: | |
| status = "**Status:** πΌ Activities Assistant makes last-minute discovery!" | |
| elif current_counter == 8: | |
| status = "**Status:** π€ All agents adapting after hearing concert suggestion" | |
| elif current_counter == 9: | |
| status = "**Status:** β User says YES to the enhanced plan!" | |
| elif current_counter == 10: | |
| status = "**Status:** π All agents processing enhanced bookings..." | |
| elif current_counter == 11: | |
| status = "**Status:** πΌ User celebrating collaborative success - conversation complete!" | |
| elif thinking_list: | |
| agents = ', '.join(thinking_list) | |
| status = f"**Status:** π {agents} {'is' if len(thinking_list) == 1 else 'are'} preparing recommendations..." | |
| elif current_speaker: | |
| status = f"**Status:** π€ {current_speaker} has the floor..." | |
| else: | |
| status = "**Status:** π― Travel coordination in progress on the shared floor" | |
| return json_state, new_counter, status | |
| def reset_discussion(): | |
| json_state = json.dumps(initial_state) | |
| return json_state, 0, "**Status:** π― Travel planning floor reset - ready for new requests" | |
| next_btn.click( | |
| next_state, | |
| inputs=[state_counter], | |
| outputs=[roundtable, state_counter, status_display] | |
| ) | |
| reset_btn.click( | |
| reset_discussion, | |
| outputs=[roundtable, state_counter, status_display] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |