Ley_Fill7 commited on
Commit
5057f72
·
1 Parent(s): d3f031e

Updated app.py and added requirements.txt with openai version

Browse files
Files changed (2) hide show
  1. app.py +37 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,4 +1,39 @@
 
1
  import streamlit as st
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
  import streamlit as st
3
 
4
+ client = OpenAI(
5
+ base_url="https://integrate.api.nvidia.com/v1",
6
+ api_key="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",
7
+ )
8
+
9
+ model_name = "meta/llama-3.1-405b-instruct"
10
+
11
+ def get_llama_response(question):
12
+ completion = client.chat.completions.create(
13
+ model=model_name,
14
+ messages=[{"role": "user", "content": question}],
15
+ temperature=0.2,
16
+ top_p=0.7,
17
+ max_tokens=1024,
18
+ stream=True
19
+ )
20
+
21
+ response = ""
22
+ for chunk in completion:
23
+ if chunk.choices[0].delta.content is not None:
24
+ response += chunk.choices[0].delta.content
25
+ return response.strip()
26
+
27
+ st.title("Ask Llama 3.1 405B on Nvidia NIM")
28
+ user_question = st.text_input("Enter your question:")
29
+
30
+ if st.button("Submit"):
31
+ if user_question:
32
+ llama_response = get_llama_response(user_question)
33
+ st.write("**Llama 3.1 405B Response:**")
34
+ st.write(llama_response)
35
+ else:
36
+ st.warning("Please enter a question.")
37
+
38
+
39
+
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai==1.35.15