Spaces:
Sleeping
Sleeping
Ley_Fill7
commited on
Commit
·
420b173
1
Parent(s):
07f7e2b
Changed the way it handles history
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
import os
|
2 |
import streamlit as st
|
|
|
3 |
from openai import OpenAI
|
4 |
|
5 |
api_key = os.getenv("NVIDIANIM_API_KEY")
|
@@ -33,25 +33,22 @@ def get_llama_response(question):
|
|
33 |
st.session_state.messages.append({"role": "assistant", "content": response_text})
|
34 |
return response_text
|
35 |
|
36 |
-
|
37 |
-
question = st.session_state.user_input
|
38 |
-
st.session_state.user_input = ""
|
39 |
-
response = get_llama_response(question)
|
40 |
-
return response
|
41 |
|
42 |
-
# Display chat history
|
43 |
for message in st.session_state.messages:
|
44 |
with st.chat_message(message["role"]):
|
45 |
st.markdown(message["content"])
|
46 |
|
47 |
-
|
48 |
-
user_input =
|
49 |
-
|
50 |
-
|
51 |
-
with st.chat_message("user"):
|
52 |
-
st.markdown(user_input)
|
53 |
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
56 |
with st.chat_message("assistant"):
|
57 |
st.markdown(response)
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import os
|
3 |
from openai import OpenAI
|
4 |
|
5 |
api_key = os.getenv("NVIDIANIM_API_KEY")
|
|
|
33 |
st.session_state.messages.append({"role": "assistant", "content": response_text})
|
34 |
return response_text
|
35 |
|
36 |
+
st.title("Ask Llama 3.1 405B on Nvidia NIM")
|
|
|
|
|
|
|
|
|
37 |
|
|
|
38 |
for message in st.session_state.messages:
|
39 |
with st.chat_message(message["role"]):
|
40 |
st.markdown(message["content"])
|
41 |
|
42 |
+
if "user_input" not in st.session_state:
|
43 |
+
st.session_state.user_input = ""
|
44 |
+
|
45 |
+
user_input = st.chat_input("Your message", key="user_input")
|
|
|
|
|
46 |
|
47 |
+
if st.button("Submit"):
|
48 |
+
if user_input:
|
49 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
50 |
+
with st.chat_message("user"):
|
51 |
+
st.markdown(user_input)
|
52 |
+
response = get_llama_response(user_input)
|
53 |
with st.chat_message("assistant"):
|
54 |
st.markdown(response)
|