import streamlit as st from streamlit.components.v1 import html import os from groq import Groq # Initialize Groq Client client = Groq(api_key=os.environ.get("GROQ_API_KEY")) # Set the title of the app st.title("AI Chatbot with Groq LLaMA Model") # Custom CSS for a professional look css = """ """ html(css) st.markdown( """

Ask anything about Data Science

Powered by Groq LLaMA 3.1 Model 🚀

""", unsafe_allow_html=True ) # Input for user queries user_input = st.text_input("Ask your question here:") # Function to handle Groq API call def get_groq_response(query): try: chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": query}], model="llama-3.1-70b-versatile", ) return chat_completion.choices[0].message.content except Exception as e: return f"An error occurred: {str(e)}" # Submit button for the chatbot if st.button("Submit"): if user_input: with st.spinner("Fetching response..."): response = get_groq_response(user_input) st.success(response) else: st.error("Please enter a question!") # Copy Button for User to easily copy the result if response: st.code(response) st.button("Copy to clipboard", on_click=st.experimental_rerun)