Chittrarasu's picture
deploy
289829a
import streamlit as st
from groq import Client
GROQ_API_KEY = "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"
def main():
st.set_page_config(page_title="Travel Assistant Chatbot", layout="wide")
st.title("✈️ Travel & Hospitality Chatbot")
# Load chatbot model
@st.cache_resource
def load_model():
return Client(api_key=GROQ_API_KEY)
chatbot = load_model()
# Initialize chat history
if "messages" not in st.session_state:
st.session_state["messages"] = [{"role": "system", "content":"You are a professional travel assistant, specializing in flights, hotels, visas, itineraries, and tourist destinations. Provide accurate, up-to-date travel advice, including the best times to visit, must-see attractions, local customs, budget-friendly options, and transportation details.Your role is to help users plan trips, understand travel regulations, and optimize their travel experience.If a query is **unrelated to travel**, do not answer it. Instead, politely redirect the user by saying:'I specialize in travel assistance. Let me know how I can help with your trip.'"
}]
# Display chat history
for message in st.session_state["messages"]:
if message["role"] != "system": # Don't show system message
with st.chat_message(message["role"]):
st.markdown(message["content"])
# User input
user_input = st.chat_input("How can I assist you with your travel plans?")
if user_input:
# Add user message to session state
st.session_state["messages"].append({"role": "user", "content": user_input})
with st.chat_message("user"):
st.markdown(user_input)
# Generate response with full conversation history
response = chatbot.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=st.session_state["messages"] # Pass entire chat history
)
bot_response = response.choices[0].message.content
# Add assistant's response to session state
st.session_state["messages"].append({"role": "assistant", "content": bot_response})
with st.chat_message("assistant"):
st.markdown(bot_response)
if __name__ == "__main__":
main()