Spaces:
Build error
Build error
| import os | |
| import streamlit as st | |
| from groq import Groq | |
| from dotenv import load_dotenv | |
| # Load environment variables from .env file | |
| load_dotenv() | |
| # Retrieve API key | |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") | |
| # Validate API key | |
| if not GROQ_API_KEY: | |
| st.error("API key is missing! Please check your .env file or environment variables.") | |
| st.stop() | |
| # Initialize Groq client with API key | |
| client = Groq(api_key=GROQ_API_KEY) | |
| st.title("Health Assistant Chatbot") | |
| user_input = st.text_input("Ask a health-related question:") | |
| if st.button("Submit") and user_input: | |
| response = client.chat.completions.create( | |
| model="llama-3.3-70b-versatile", | |
| messages=[{"role": "user", "content": user_input}], | |
| temperature=0.6, | |
| max_completion_tokens=4096, | |
| top_p=0.95, | |
| ) | |
| st.write("### Response:") | |
| st.write(response.choices[0].message.content) | |