Spaces:
Build error
Build error
File size: 1,127 Bytes
5f977be | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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.")
|