Heathcare_bot / app.py
zainabbbbbbbbbb's picture
Update app.py
6c43050 verified
import streamlit as st
import os
from groq import Groq
# Set up Groq API
os.environ['GROQ_API_KEY'] = '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'
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
# Function to get Medbot's response
def medbot_response(user_input):
try:
chat_completion = client.chat.completions.create(
messages=[
{"role": "system", "content": (
"You are Medbot, a highly intelligent personal healthcare assistant and doctor. "
"You provide accurate diagnoses based on symptoms and detailed medical information. "
"Be polite, informative, and user-friendly."
)},
{"role": "user", "content": user_input}
],
model="llama-3.3-70b-versatile",
)
return chat_completion.choices[0].message.content
except Exception as e:
return f"Error: {str(e)}"
# Streamlit App
st.set_page_config(page_title="Medbot", page_icon="🩺", layout="centered")
# App Title
st.markdown("<h1 style='text-align: center; color: #4CAF50;'>Medbot 🩺</h1>", unsafe_allow_html=True)
st.markdown("<h3 style='text-align: center;'>Your Personal Healthcare Assistant</h3>", unsafe_allow_html=True)
# Sidebar with green hearts and options
st.sidebar.markdown("<h3 style='color: #4CAF50;'>Hello! I'm Medbot! πŸ’š</h3>", unsafe_allow_html=True)
st.sidebar.write("I can help you with: ")
st.sidebar.markdown("""
<ul style='color: #4CAF50; font-size: 16px;'>
<li>πŸ’š <strong>Symptom Analysis</strong></li>
<li>πŸ’š <strong>Medical Condition Information</strong></li>
<li>πŸ’š <strong>Health Tips</strong></li>
</ul>
""", unsafe_allow_html=True)
# Chat Interface
st.markdown("<hr style='border:1px solid #D3D3D3'>", unsafe_allow_html=True)
user_input = st.text_input("Enter your symptoms or question:", "")
if st.button("Submit"):
if user_input:
response = medbot_response(user_input)
# Display Medbot's response in styled chat bubble
st.markdown(
f"<div style='background-color: #f0f8e8; border-radius: 10px; padding: 10px;'>"
f"<p style='color: #006400; font-size: 16px;'><strong>Medbot:</strong> {response}</p></div>",
unsafe_allow_html=True
)
else:
st.warning("Please enter a message to proceed.")
# Footer
st.markdown(
"<footer style='text-align: center; color: #888;'>"
"Built with ❀️ using Streamlit & Groq AI</footer>",
unsafe_allow_html=True
)