import streamlit as st import os from groq import Groq # Initialize Groq client using the API key client = Groq( api_key=os.environ.get("GROQ_API_KEY") # Ensure you have your Groq API Key stored in environment variables ) # Streamlit UI st.title("Chatbot") st.write("Welcome to the Chatbot! Ask me anything I will try to provide best answer as per my knowledge!") # User input user_input = st.text_input("Your question:", "") if st.button("Ask"): if user_input.strip(): try: # Call Groq's API to generate the response chat_completion = client.chat.completions.create( messages=[{ "role": "user", "content": user_input, }], model="llama3-groq-8b-8192-tool-use-preview", # Specify the Groq model ) # Display the chatbot response bot_reply = chat_completion.choices[0].message.content st.text_area("Response:", bot_reply, height=200) except Exception as e: st.error(f"Error: {e}") else: st.warning("Please enter a question before asking.")