import os import streamlit as st from groq import Groq # ✅ Fix TensorFlow CPU warnings os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0" # ✅ Set up the Groq API Key GROQ_API_KEY = "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" os.environ["GROQ_API_KEY"] = GROQ_API_KEY # ✅ Initialize the Groq client (Fixed 'proxies' issue) client = Groq(api_key=GROQ_API_KEY) # ✅ Streamlit UI setup st.set_page_config(page_title="AI Disease Detection Assistant", page_icon="🩺", layout="wide") st.title("🩺 AI Disease Detection Chatbot") st.write("Hello! I'm your AI assistant for disease-related queries. Ask me about symptoms, treatments, or general health advice.") # ✅ Sidebar settings st.sidebar.header("⚙️ Settings") chat_theme = st.sidebar.radio("Choose a theme:", ["Light", "Dark", "Blue", "Green"]) # ✅ Apply themes themes = { "Dark": "#1e1e1e", "Blue": "#e3f2fd", "Green": "#e8f5e9", "Light": "#ffffff" } st.markdown(f""" """, unsafe_allow_html=True) # ✅ Session state for chat history if 'conversation_history' not in st.session_state: st.session_state.conversation_history = [] # ✅ Function to generate AI response def generate_chatbot_response(user_message): # Custom responses if "who created you" in user_message.lower(): return "I was created by Abdel Basit. 😊" # AI model response prompt = f"You are a medical AI assistant. The user asks: {user_message}. Provide a detailed, accurate medical response." try: chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": prompt}], model="llama3-8b-8192" ) return chat_completion.choices[0].message.content except Exception as e: return f"⚠️ Error: {str(e)}" # ✅ User chat input st.markdown("### 💬 Chat with me") user_input = st.chat_input("Ask me a health-related question:") if user_input: chatbot_response = generate_chatbot_response(user_input) st.session_state.conversation_history.append(("User: " + user_input, "Chatbot: " + chatbot_response)) # ✅ Display chat history st.markdown("---") st.markdown("### 🗨️ Chat History") for question, answer in st.session_state.conversation_history: st.write(f"
{question}
", unsafe_allow_html=True) st.write(f"
{answer}
", unsafe_allow_html=True)