| import os |
| from groq import Groq |
| import streamlit as st |
| from dotenv import load_dotenv |
|
|
| |
| load_dotenv() |
| api_key = os.getenv("GROQ_API_KEY") |
|
|
| |
| client = Groq(api_key=api_key) |
|
|
| |
| health_issues = [ |
| "fever", "malaria", "skin infection", "flu", "cough", "diabetes", "hypertension", |
| "cold", "asthma", "arthritis", "chickenpox", "measles", "pneumonia", "migraine", |
| "anxiety", "depression", "heart disease", "cancer", "high cholesterol", "stroke", |
| "obesity", "insomnia", "constipation", "acid reflux", "eczema", "psoriasis", |
| "allergy", "cold sores", "chronic fatigue", "UTI", "kidney disease", "hepatitis", |
| "tuberculosis", "stomach ulcers", "gout", "HIV/AIDS", "malnutrition", "blood pressure", |
| "menstrual irregularities", "pregnancy", "anemia", "vitamin deficiency", "chronic pain" |
| ] |
|
|
|
|
| |
| def get_response(query): |
| completion = client.chat.completions.create( |
| model="llama-3.3-70b-versatile", |
| messages=[{"role": "user", "content": query}], |
| temperature=0.7, |
| max_completion_tokens=1024, |
| top_p=1, |
| ) |
| response = completion.choices[0].message.content |
| return response |
|
|
| def main(): |
| st.title("Health Assistant Chatbot") |
|
|
| |
| topic = st.selectbox("Choose a health issue", health_issues) |
| user_input = st.text_area("Or ask a health-related question:", "") |
|
|
| |
| query = user_input if user_input else f"Tell me about {topic}" |
|
|
| |
| submit_button = st.button("Submit") |
|
|
| |
| if submit_button and query: |
| response = get_response(query) |
| |
| |
| st.write("### Response:") |
| st.write(response) |
|
|
| |
| if user_input and not any(health_issue in user_input.lower() for health_issue in health_issues): |
| st.write("Sorry, I can only answer health-related questions.") |
|
|
| if __name__ == "__main__": |
| main() |
|
|