# Install necessary libraries (add these to requirements.txt): # streamlit, groq, python-dotenv import os import streamlit as st from dotenv import load_dotenv from groq import Groq # Load environment variables from .env load_dotenv() # Get the API key API_KEY = os.getenv("GROQ_API_KEY") if not API_KEY: st.error("API key not found. Please set GROQ_API_KEY in the .env file.") # Initialize the Groq client client = Groq(api_key=API_KEY) # Streamlit app configuration st.set_page_config(page_title="General Information Chatbot", layout="centered") st.title("General Information Chatbot") st.subheader("Ask me anything! I'm here to help you with any kind of information.") # User input user_input = st.text_input("Enter your question or query:", "") # Chatbot logic if st.button("Ask"): if not user_input.strip(): st.warning("Please enter a valid question.") else: try: # Send the user's query to the LLaMA model response = client.chat.completions.create( messages=[ {"role": "system", "content": "You are a helpful assistant capable of answering general knowledge and informational queries."}, {"role": "user", "content": user_input}, ], model="llama-3.3-70b-versatile", # Correct model name temperature=1, max_tokens=1024, top_p=1, ) # Extract and display the response chatbot_response = response.choices[0].message.content st.success(f"Chatbot: {chatbot_response}") except Exception as e: st.error(f"An error occurred: {e}") # Footer st.markdown( """ **Disclaimer:** This chatbot is for informational purposes only. Please verify critical information from reliable sources. """ )