Update app.py
Browse files2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940412 unmodified linesfrom groq import Groqimport streamlit as st# Load environment variablesload_dotenv()GROQ_API_KEY = "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"client = Groq(api_key =GROQ_API_KEY)# Streamlit UIst.title("Python Bot with Groq's API")st.subheader("Interact with an AI Model Powered by Groq")# Input Sectionst.header("Input")user_input = st.text_input("Enter your question or message below:")# Submit buttonif st.button("Submit"):if user_input.strip():# Output Sectionst.header("Output")with st.spinner("Fetching response from the LLM..."):try:# Interact with Groq's LLMchat_completion = client.chat.completions.create(messages=[{"role": "user", "content": user_input},],model="llama3-8b-8192",stream=False,)response = chat_completion.choices[0].message.contentst.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!")2 unmodified lines3456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172732 unmodified linesfrom groq import Groqimport streamlit as st# Load environment variables from .env fileload_dotenv()# Ensure that the API key is loaded correctlyapi_key = os.getenv("GROQ_API_KEY")if not api_key:st.error("API key is missing! Please check your .env file or set the environment variable.")else:# Initialize Groq client with the API keyclient = Groq(api_key=api_key)# Custom CSS to style headings and overall appearancest.markdown("""<style>.big-heading {font-size: 36px;font-weight: bold;color: #333;}.sub-header {font-size: 24px;font-weight: bold;color: #555;}.header {font-size: 20px;font-weight: normal;color: #444;}.output-text {font-size: 18px;font-weight: normal;color: #000;}</style>""", unsafe_allow_html=True)# Streamlit UIst.markdown('<p class="big-heading">Python Bot with Groq\'s API</p>', unsafe_allow_html=True)st.markdown('<p class="sub-header">Interact with an AI Model Powered by Groq</p>', unsafe_allow_html=True)# Input Sectionst.markdown('<p class="header">Input</p>', unsafe_allow_html=True)user_input = st.text_input("Enter your question or message below:")# Submit buttonif st.button("Submit"):if user_input.strip():# Output Sectionst.markdown('<p class="header">Output</p>', unsafe_allow_html=True)with st.spinner("Fetching response from the LLM..."):try:# Interact with Groq's LLMchat_completion = client.chat.completions.create(messages=[{"role": "user", "content": user_input},],model="llama3-8b-8192",stream=False,)response = chat_completion.choices[0].message.contentst.success("Here is the AI's response:")st.markdown(f'<p class="output-text">{response}</p>', unsafe_allow_html=True)except Exception as e:st.error(f"Error: {e}")else:st.warning("Please enter a valid message!")
app.py+63-31