Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from openai import OpenAI
|
4 |
+
|
5 |
+
# Initialize the Nvidia API client using API Key stored in Streamlit secrets
|
6 |
+
client = OpenAI(
|
7 |
+
base_url="https://integrate.api.nvidia.com/v1", # Nvidia API endpoint
|
8 |
+
api_key=st.secrets["NVIDIA_API_KEY"] # Nvidia API Key from Streamlit secrets
|
9 |
+
)
|
10 |
+
|
11 |
+
# Define Streamlit app layout
|
12 |
+
st.title("AWS Well-Architected Review")
|
13 |
+
st.write("Get recommendations for optimizing your AWS architecture.")
|
14 |
+
|
15 |
+
# Session state to store messages (conversation history)
|
16 |
+
if "messages" not in st.session_state:
|
17 |
+
st.session_state.messages = []
|
18 |
+
|
19 |
+
# User input for AWS architecture description
|
20 |
+
architecture_input = st.text_area("Describe your AWS architecture:")
|
21 |
+
|
22 |
+
# Button to submit the input
|
23 |
+
if st.button("Get Recommendations"):
|
24 |
+
if architecture_input:
|
25 |
+
# Add user input to the conversation
|
26 |
+
st.session_state.messages.append({"role": "user", "content": architecture_input})
|
27 |
+
|
28 |
+
with st.chat_message("assistant"):
|
29 |
+
with st.spinner("Generating recommendations..."):
|
30 |
+
# Create Nvidia completion request with conversation history
|
31 |
+
stream = client.chat.completions.create(
|
32 |
+
model="nvidia-llama-3.1-70b-instruct", # Nvidia model name
|
33 |
+
messages=st.session_state.messages, # Include all messages in the API call
|
34 |
+
temperature=0.5,
|
35 |
+
top_p=0.7,
|
36 |
+
max_tokens=1024,
|
37 |
+
stream=True,
|
38 |
+
)
|
39 |
+
|
40 |
+
response_chunks = []
|
41 |
+
for chunk in stream:
|
42 |
+
if chunk.choices[0].delta.content is not None:
|
43 |
+
response_chunks.append(chunk.choices[0].delta.content)
|
44 |
+
response = "".join(response_chunks)
|
45 |
+
|
46 |
+
# Display the response as recommendations
|
47 |
+
st.markdown(f"**Recommendations:**\n\n{response}")
|
48 |
+
# Add response to conversation history
|
49 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|