Gastro / app.py
velmurugan1122's picture
changes done
9942df9
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("""
<style>
.chat-bubble {
padding: 10px;
border-radius: 10px;
margin-bottom: 10px;
}
.user-bubble {
background-color: #DCF8C6;
text-align: right;
}
.assistant-bubble {
background-color: #ECECEC;
text-align: left;
}
.icon {
font-size: 20px;
margin-right: 10px;
}
</style>
""", 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"<div class='chat-bubble user-bubble'><strong>You:</strong> {message['content']}</div>", unsafe_allow_html=True)
elif message["role"] == "assistant":
st.markdown(f"<div class='chat-bubble assistant-bubble'><strong>Assistant:</strong> {message['content']}</div>", unsafe_allow_html=True)