import streamlit as st
from streamlit.components.v1 import html
from groq import Groq
import os
# Use the Hugging Face secret API key
api_key = os.getenv('api_key')
# Initialize Groq Client with the Hugging Face secret key
client = Groq(api_key=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
response = None
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)