Spaces:
Sleeping
Sleeping
File size: 6,847 Bytes
64aee40 |
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
import gradio as gr
import os
from gradio.themes import Size, GoogleFont
from agents.gather_agent import Gather_Agent
from agents.check_agent import Check_Agent
from agents.response_agent import Response_Agent
from agents.planner_agent import Planner_Agent
import get_map
# Create custom Color objects for our primary, secondary, and neutral colors
primary_color = gr.themes.colors.green
secondary_color = gr.themes.colors.amber
neutral_color = gr.themes.colors.stone # Assuming black for text
# Set the sizes
spacing_size = gr.themes.sizes.spacing_md
radius_size = gr.themes.sizes.radius_md
text_size = gr.themes.sizes.text_md
# Set the fonts
font = GoogleFont("Source Sans Pro")
font_mono = GoogleFont("IBM Plex Mono")
# Create the theme
theme = gr.themes.Base(
primary_hue=primary_color,
secondary_hue=secondary_color,
neutral_hue=neutral_color,
spacing_size=spacing_size,
radius_size=radius_size,
text_size=text_size,
font=font,
font_mono=font_mono
)
gather_agent = Gather_Agent()
check_agent = Check_Agent()
response_agent = Response_Agent()
planner_agent = Planner_Agent()
def send_message(user_input, chat_history):
isComplete = False
helper_anwser = ""
_input_gather = gather_agent.format_prompt(history=chat_history, input=user_input)
parsed_result_gather = gather_agent.get_parsed_result(_input_gather)
_input_check = check_agent.format_prompt(input=parsed_result_gather)
isComplete = check_agent.get_parsed_result(_input_check)
if isComplete == False:
_input_response = response_agent.format_prompt(input=parsed_result_gather)
helper_anwser = response_agent.get_parsed_result(_input_response)
# _input_check = check_agent.format_prompt(input=parsed_result_gather)
# isComplete, helper_anwser = check_agent.get_parsed_result(_input_check)
return isComplete, helper_anwser, parsed_result_gather
def get_itenerary(parsed_result_gather):
_input_planner = planner_agent.format_prompt(parsed_result_gather)
return planner_agent.get_itenerary(_input_planner)
def get_itenerary_places(itenerary):
_input_places = planner_agent.format_prompt_to_get_places(itenerary)
return planner_agent.get_places_from_itenerary(_input_places)
# isComplete = False
# chat_history = ""
# helper_anwser = "Hello, can you tell me your trip details and constraints so I can give you great recomendations?"
# user_input = input("Helper: " + helper_anwser + "\nUser: ")
with gr.Blocks(theme=theme, title="TrainLine") as demo:
gr.Markdown(
"""
<div style="vertical-align: middle">
<div style="float: left">
<img src="https://static.trainlinecontent.com/content/vul/logos/trainline-mint.svg" alt=""
width="120" height="120">
</div>
</div>
""")
helper_anwser = "Hello, can you tell me your trip details and constraints so I can give you great recomendations?"
with gr.TabItem("Travel Companion"):
chatbot = gr.Chatbot(value=[[None, helper_anwser]])
user_input = gr.Textbox()
gr.Examples([
"I want to go to Rome. can you recommend a site seeing tour for one day?",
"I like to walk a lot and i prefer to visit fine arts museums",
"Porto for 3 days. i will arrive on monday and leave on thursday. i can only visit places after 5pm so be "
"sure i can visit those places",
"I would like to plan a trip to Europe with my family of four. We want to visit Paris, Rome, and Madrid in "
"10 days. Can you suggest an itinerary that includes transportation and accommodations? "
"Also, please provide information on the best restaurants in each city for a budget of $50 per person per meal."
], user_input)
with gr.TabItem("Map"):
map = gr.Plot(visible=True).style()
result_df = gr.Dataframe(type="pandas", visible=True)
isComplete = False
history = ""
locations = []
def user(user_message, history):
print(user_message, history)
return gr.update(value="", interactive=False), history + [[user_message, None]]
# def bot(chat_history):
# print(chat_history)
# # Create history
# history = ""
# for i in range(len(chat_history)-1):
# history += "User: " + chat_history[i][0] + "\nHelper: " + chat_history[i][1] + "\n"
# history += "User: " + chat_history[-1][0]
# # isComplete, helper_anwser, data_collected = send_message(message, history)
# # if isComplete == True:
# # helper_anwser = get_itenerary(data_collected)
# # chat_history.append((message, helper_anwser))
# return "", chat_history
def respond(chat_history):
print(chat_history)
# Create history
history = ""
for i in range(1, len(chat_history) - 1):
history += "User: " + chat_history[i][0] + "\nHelper: " + chat_history[i][1] + "\n"
message = chat_history[-1][0]
print(history)
print(message)
isComplete, helper_anwser, data_collected = send_message(message, history)
chat_history.pop(-1)
if isComplete == True:
itenerary = get_itenerary(data_collected)
locations = get_itenerary_places(itenerary)
helper_anwser = itenerary + "\nList of places with adresses: " + str(locations)
map, result_df = get_map.filter_map(locations)
chat_history.append((message, helper_anwser))
return chat_history, map, result_df
chat_history.append((message, helper_anwser))
return chat_history, None, None
# user_input.submit(respond, [user_input, chatbot], [user_input, chatbot])
response = user_input.submit(user, [user_input, chatbot], [user_input, chatbot], queue=False).then(
respond, chatbot, [chatbot, map, result_df]
)
response.then(lambda: gr.update(interactive=True), None, [user_input], queue=False)
# if map != None:
# map.update(visible=True)
# result_df.update(visible=True)
demo.launch(auth=( os.environ["USER"],os.environ["PASSWORD"]))
# while isComplete == False:
# isComplete, helper_anwser, data_collected = main.send_message(user_input, chat_history)
# if isComplete == False:
# chat_history += "User: " + user_input + "\nHelper: " + helper_anwser + "\n"
# user_input = input("Helper: " + helper_anwser + "\nUser: ")
# itenerary_response = main.get_itenerary(data_collected)
# I would like to go to paris, from 12th of july to 15th of July, I want to visit museums, eat at local restaurants and visit the louvre on my first day. My son is allergic to peanuts, and I like to sleep in, so please don't book anything before 11am. I would also like to not get further then 2km from the city's center. |