Spaces:
Sleeping
Sleeping
Ley_Fill7
commited on
Commit
·
49ca5bb
1
Parent(s):
8e08e98
Reverted back to the initial app
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
-
from openai import OpenAI
|
4 |
|
5 |
api_key = os.getenv("NVIDIANIM_API_KEY")
|
6 |
|
@@ -11,41 +11,29 @@ client = OpenAI(
|
|
11 |
|
12 |
model_name = "meta/llama-3.1-405b-instruct"
|
13 |
|
14 |
-
if "messages" not in st.session_state:
|
15 |
-
st.session_state.messages = []
|
16 |
-
|
17 |
def get_llama_response(question):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
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 |
-
user_input = st.chat_input("Your message")
|
43 |
|
44 |
if st.button("Submit"):
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
st.markdown(response)
|
|
|
1 |
+
from openai import OpenAI
|
2 |
import streamlit as st
|
3 |
import os
|
|
|
4 |
|
5 |
api_key = os.getenv("NVIDIANIM_API_KEY")
|
6 |
|
|
|
11 |
|
12 |
model_name = "meta/llama-3.1-405b-instruct"
|
13 |
|
|
|
|
|
|
|
14 |
def get_llama_response(question):
|
15 |
+
completion = client.chat.completions.create(
|
16 |
+
model=model_name,
|
17 |
+
messages=[{"role": "user", "content": question}],
|
18 |
+
temperature=0.2,
|
19 |
+
top_p=0.7,
|
20 |
+
max_tokens=1024,
|
21 |
+
stream=True
|
22 |
+
)
|
23 |
+
|
24 |
+
response = ""
|
25 |
+
for chunk in completion:
|
26 |
+
if chunk.choices[0].delta.content is not None:
|
27 |
+
response += chunk.choices[0].delta.content
|
28 |
+
return response.strip()
|
|
|
|
|
|
|
29 |
|
30 |
st.title("Ask Llama 3.1 405B on Nvidia NIM")
|
31 |
+
user_question = st.text_input("Enter your question:")
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
if st.button("Submit"):
|
34 |
+
if user_question:
|
35 |
+
llama_response = get_llama_response(user_question)
|
36 |
+
st.write("**Llama 3.1 405B Response:**")
|
37 |
+
st.write(llama_response)
|
38 |
+
else:
|
39 |
+
st.warning("Please enter a question.")
|
|