| 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") |
|
|
| |
| @st.cache_resource |
| def load_model(): |
| return Client(api_key=GROQ_API_KEY) |
|
|
| chatbot = load_model() |
|
|
| |
| 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.'" |
| }] |
|
|
| |
| for message in st.session_state["messages"]: |
| if message["role"] != "system": |
| with st.chat_message(message["role"]): |
| st.markdown(message["content"]) |
|
|
| |
| user_input = st.chat_input("How can I assist you with your travel plans?") |
| |
| if user_input: |
| |
| st.session_state["messages"].append({"role": "user", "content": user_input}) |
| with st.chat_message("user"): |
| st.markdown(user_input) |
|
|
| |
| response = chatbot.chat.completions.create( |
| model="llama-3.3-70b-versatile", |
| messages=st.session_state["messages"] |
| ) |
|
|
| bot_response = response.choices[0].message.content |
|
|
| |
| st.session_state["messages"].append({"role": "assistant", "content": bot_response}) |
| with st.chat_message("assistant"): |
| st.markdown(bot_response) |
|
|
| if __name__ == "__main__": |
| main() |
|
|