import os from dotenv import load_dotenv from groq import Groq import streamlit as st # Load environment variables load_dotenv() GROQ_API_KEY = "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" client = Groq(api_key =GROQ_API_KEY) # Streamlit UI st.title("Python Bot with Groq's API") st.subheader("Interact with an AI Model Powered by Groq") # Input Section st.header("Input") user_input = st.text_input("Enter your question or message below:") # Submit button if st.button("Submit"): if user_input.strip(): # Output Section st.header("Output") with st.spinner("Fetching response from the LLM..."): try: # Interact with Groq's LLM chat_completion = client.chat.completions.create( messages=[ {"role": "user", "content": user_input}, ], model="llama3-8b-8192", stream=False, ) response = chat_completion.choices[0].message.content st.success("Here is the AI's response:") st.write(response) except Exception as e: st.error(f"Error: {e}") else: st.warning("Please enter a valid message!")