import os
import streamlit as st
from groq import Groq
from dotenv import load_dotenv
load_dotenv()
groq_api_key = os.getenv("groq_api_key")
st.sidebar.title(":white[_Tailor_]")
prompt = st.sidebar.title(":red[_System Prompt:_] ")
model = st.sidebar.selectbox(
'Choose a model', ['Llama3-8b-8192', 'Llama3-70b-8192','Mixtral-8x7b-32768','Gemma-7b-It']
)
# Groq client
client = Groq(api_key = groq_api_key)
# Streamlit Interface
st.title("🗨️ LLMS :red[Interaction] - :blue[By Raj]")
# Define the CSS for the animation
animation_css = """
"""
# Apply the animation to your text
animated_text = """
Welcome to the LLMS Interaction web app!
This app allows you to interact with the LLMS AI model. To use the app, follow these steps:
1. Enter your question in the text input box.
2. Click the 'Submit' button to send your question to the AI model.
3. The response will be displayed below the text input box.
4. You can view the history of your queries and responses in the sidebar.
5. To view the details of a specific query, click on the corresponding button in the sidebar.
Please note that this web app is super fast and utilizes custom api integration to fetch responses.
Try it
"""
# Combine the CSS and the text
final_output = animation_css + animated_text
# Display using st.markdown
st.markdown(final_output, unsafe_allow_html=True)
# Initialize sessesion state for history
if "history" not in st.session_state:
st.session_state.history = []
user_input = st.text_input("Enter your question: ", "")
if st.button("Submit"):
chat_completion = client.chat.completions.create(
messages=[
{
"role" : "user",
"content" : user_input,
}
],
model = model,
)
# Store the query and response in history
response = chat_completion.choices[0].message.content
st.session_state.history.append({"query" : user_input, "response" : response})
# Display the response
st.markdown(f'{response}
', unsafe_allow_html=True)
# Display history
st.sidebar.title(":rainbow[Memory]")
for i, entry in enumerate(st.session_state.history):
if st.sidebar.button(f'Query {i+1}: {entry["query"]}'):
st.markdown(f'{entry["response"]}
', unsafe_allow_html=True)
# Add a footer with fade-in animation
footer = """
"""
st.markdown(footer, unsafe_allow_html=True)