chatbot_kabilan / app.py
Kabila22's picture
Add new file
084d570
import streamlit as st
from groq import Client
# Hardcoded API Key (Consider using environment variables for security)
GROQ_API_KEY = "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"
def main():
st.set_page_config(page_title="🩺 Symptom Checker Chatbot", layout="wide")
st.title("👩🏼‍⚕️Symptom Checker Chatbot")
st.markdown("**Disclaimer:** This chatbot does not provide medical advice. For emergencies, call your local emergency number.")
# Load chatbot model
@st.cache_resource
def load_model():
return Client(api_key=GROQ_API_KEY)
chatbot = load_model()
# Chat history
if "messages" not in st.session_state:
st.session_state["messages"] = []
# Display chat history
for message in st.session_state["messages"]:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# User input
user_input = st.chat_input("📝Describe your symptoms or health issue")
if user_input:
st.session_state["messages"].append({"role": "user", "content": user_input})
with st.chat_message("user"):
st.markdown(user_input)
# Generate response
response = chatbot.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=[
{"role": "system", "content": "You are a highly knowledgeable and reliable Symptom Checker Chatbot, designed to provide accurate, relevant, and helpful responses related only to medical symptoms. Your goal is to assist users in understanding their symptoms by offering possible causes, general health advice, and recommendations on when to seek medical attention. You must only answer questions related to symptoms and avoid providing diagnoses, treatment plans, or medication advice. If a user asks about non-symptom-related topics, politely redirect them to focus on relevant symptom-related queries. Always maintain a professional, empathetic, and respectful tone, ensuring that users are advised to consult a qualified healthcare provider for personalized medical guidance."},
{"role": "user", "content": user_input}
]
)
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()