from langchain_groq import ChatGroq from dotenv import load_dotenv import streamlit as st # import os # Streamlit app st.title("AI ChatBot") def generate_response(question): llm = ChatGroq(model_name="gemma2-9b-it", temperature=0.5) # Create a placeholder for the response response_placeholder = st.empty() full_response = "" # Stream the response # with st.spinner("Generating response..."): for chunk in llm.stream(question): full_response += chunk.content # Update the placeholder with the accumulated response response_placeholder.markdown(full_response + "▌") # Display the final response without the cursor response_placeholder.markdown(full_response) # Input for the user's question user_question = st.text_input("Enter your question:", key="input") # Button to generate response if st.button("Generate Response"): st.markdown("###### The Response") if user_question: with st.spinner("Generating response..."): generate_response(user_question) else: st.warning("Please enter a question.")