Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,37 @@ import os
|
|
| 2 |
import streamlit as slt
|
| 3 |
from langchain_groq import ChatGroq
|
| 4 |
api_key = os.getenv("pack1st")
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import streamlit as slt
|
| 3 |
from langchain_groq import ChatGroq
|
| 4 |
api_key = os.getenv("pack1st")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
if not api_key:
|
| 8 |
+
st.error("GROQ_API_KEY is not set. Please add it to your Hugging Face Space Secrets.")
|
| 9 |
+
st.stop()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
llm = ChatGroq(model_name="gemma2-9b-it", api_key=api_key)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
st.set_page_config(page_title="Basic Langchain Model", page_icon=":robot:")
|
| 16 |
+
st.header("Langchain Model Chatbot")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
if "messages" not in st.session_state:
|
| 20 |
+
st.session_state.messages = []
|
| 21 |
+
|
| 22 |
+
for message in st.session_state.messages:
|
| 23 |
+
with st.chat_message(message["role"]):
|
| 24 |
+
st.write(message["content"])
|
| 25 |
+
|
| 26 |
+
if prompt := st.chat_input("Type your message..."):
|
| 27 |
+
|
| 28 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 29 |
+
with st.chat_message("user"):
|
| 30 |
+
st.write(prompt)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
with st.chat_message("assistant"):
|
| 34 |
+
response = llm.invoke(prompt).content
|
| 35 |
+
st.write(response)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|