File size: 2,526 Bytes
4eac7d7
 
 
 
 
 
 
 
 
9942df9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a50854
4eac7d7
 
 
 
bbda966
7a50854
bbda966
4eac7d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9942df9
4eac7d7
9942df9
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
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)