import streamlit as st from groq import Groq # Initialize Groq client client = Groq(api_key="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") # Page configuration st.set_page_config(page_title="Gastroenterology Chatbot", page_icon="🌟") # Custom CSS for chat styling st.markdown(""" """, unsafe_allow_html=True) st.title("🏥 Gastroenterology Chatbot") st.write("I am a highly knowledgeable and compassionate AI gastroenterology assistant. Ask me anything about digestive health!") # Initialize chat history if not present if "messages" not in st.session_state: st.session_state.messages = [ {"role": "system", "content": "You are a highly knowledgeable and compassionate AI gastroenterology assistant. Your primary goal is to provide accurate, clear, and empathetic information and guidance related to digestive health. By offering evidence-based insights, encouraging wellness practices, and respecting user privacy, you empower individuals to make informed decisions about their digestive well-being while promoting responsible healthcare practices."} ] # User input user_input = st.text_input("You:", "") if user_input: st.session_state.messages.append({"role": "user", "content": user_input}) try: chat_completion = client.chat.completions.create( messages=st.session_state.messages, model="llama-3.3-70b-versatile", ) response = chat_completion.choices[0].message.content st.session_state.messages.append({"role": "assistant", "content": response}) except Exception as e: st.error(f"An error occurred: {e}") # Display chat history st.write("## Chat History") for message in st.session_state.messages: if message["role"] == "user": st.markdown(f"
You: {message['content']}
", unsafe_allow_html=True) elif message["role"] == "assistant": st.markdown(f"
Assistant: {message['content']}
", unsafe_allow_html=True)