Spaces:
Build error
Build error
| import os | |
| import streamlit as st | |
| from groq import Groq | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv() | |
| api_key = os.getenv("GROQ_API_KEY") | |
| # Ensure API key is available | |
| if not api_key: | |
| st.error("API key not found. Please set GROQ_API_KEY in the .env file.") | |
| st.stop() | |
| # Initialize Groq client | |
| client = Groq(api_key=api_key) | |
| # Function to get chatbot response | |
| def get_chat_response(query): | |
| chat_completion = client.chat.completions.create( | |
| messages=[{"role": "user", "content": query}], | |
| model="llama-3.3-70b-versatile", | |
| ) | |
| return chat_completion.choices[0].message.content | |
| # Streamlit app interface | |
| def main(): | |
| st.title("Health Assistant Chatbot") | |
| st.write("Ask about health issues and get proper treatment suggestions.") | |
| user_input = st.text_input("Enter your health-related question:") | |
| if user_input: | |
| health_keywords = [ | |
| "fever", "flu", "cough", "malaria", "typhoid", "asthma", "diabetes", "hypertension", "migraine", | |
| "pneumonia", "dengue", "tuberculosis", "arthritis", "chickenpox", "measles", "bronchitis", "anemia", | |
| "jaundice", "ulcer", "gastritis", "depression", "anxiety", "stroke", "eczema", "psoriasis", "obesity", | |
| "cholera", "hepatitis", "insomnia", "thyroid", "sinusitis", "tonsillitis", "vertigo", "osteoporosis", | |
| "conjunctivitis", "paralysis", "malnutrition", "appendicitis", "epilepsy", "gallstones", "gout", | |
| "kidney stones", "meningitis", "mumps", "pancreatitis", "pneumothorax", "scabies", "scoliosis", "sepsis", | |
| "syphilis", "tetanus" | |
| ] | |
| if any(keyword in user_input.lower() for keyword in health_keywords): | |
| response = get_chat_response(user_input) | |
| st.write("Chatbot Response:", response) | |
| else: | |
| st.write("Sorry, I only answer health-related questions.") | |
| if __name__ == "__main__": | |
| main() | |