vineeth N
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain_groq import ChatGroq
|
3 |
+
from langchain.schema import HumanMessage, AIMessage
|
4 |
+
|
5 |
+
GROQ_API_KEY='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'
|
6 |
+
# Initialize the ChatGroq model
|
7 |
+
llm = ChatGroq(temperature=0, model_name='llama-3.1-8b-instant', groq_api_key=GROQ_API_KEY)
|
8 |
+
|
9 |
+
|
10 |
+
st.title("LLM Bot with ChatGroq")
|
11 |
+
|
12 |
+
# Initialize chat history
|
13 |
+
if "messages" not in st.session_state:
|
14 |
+
st.session_state.messages = []
|
15 |
+
|
16 |
+
# Display chat messages from history on app rerun
|
17 |
+
for message in st.session_state.messages:
|
18 |
+
with st.chat_message(message["role"]):
|
19 |
+
st.markdown(message["content"])
|
20 |
+
|
21 |
+
# React to user input
|
22 |
+
if prompt := st.chat_input("What is your question?"):
|
23 |
+
# Display user message in chat message container
|
24 |
+
st.chat_message("user").markdown(prompt)
|
25 |
+
|
26 |
+
# Add user message to chat history
|
27 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
28 |
+
|
29 |
+
# Generate AI response
|
30 |
+
response = llm([HumanMessage(content=prompt)])
|
31 |
+
|
32 |
+
# Display AI response in chat message container
|
33 |
+
with st.chat_message("assistant"):
|
34 |
+
st.markdown(response.content)
|
35 |
+
|
36 |
+
# Add AI response to chat history
|
37 |
+
st.session_state.messages.append({"role": "assistant", "content": response.content})
|