Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,20 @@
|
|
1 |
import streamlit as st
|
2 |
from llama_index import VectorStoreIndex, ServiceContext, Document
|
3 |
from llama_index.llms import OpenAI
|
|
|
4 |
import openai
|
5 |
from llama_index import SimpleDirectoryReader
|
6 |
|
7 |
st.set_page_config(page_title="HUD Audit Guide", page_icon="π", layout="centered", initial_sidebar_state="auto", menu_items=None)
|
8 |
-
openai.api_key = os.environ["OpenAI-API-Key"]
|
9 |
st.title("Ask the HUD Audit Guide π¬π€")
|
10 |
st.info("Check out more info on the complete HUD Audit Guide at the official [website](https://www.hudoig.gov/library/single-audit-guidance/hud-consolidated-audit-guide)", icon="π")
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
if "messages" not in st.session_state.keys(): # Initialize the chat messages history
|
13 |
st.session_state.messages = [
|
14 |
{"role": "assistant", "content": "Ask me a question about the HUD Audit Guide - Chapter 6 - Ginnie Mae Issuers of Mortgage-Backed Securities Audit Guidance!"}
|
@@ -28,7 +34,10 @@ index = load_data()
|
|
28 |
chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
|
29 |
|
30 |
if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
for message in st.session_state.messages: # Display the prior chat messages
|
34 |
with st.chat_message(message["role"]):
|
|
|
1 |
import streamlit as st
|
2 |
from llama_index import VectorStoreIndex, ServiceContext, Document
|
3 |
from llama_index.llms import OpenAI
|
4 |
+
from langchain.llms import OpenAI
|
5 |
import openai
|
6 |
from llama_index import SimpleDirectoryReader
|
7 |
|
8 |
st.set_page_config(page_title="HUD Audit Guide", page_icon="π", layout="centered", initial_sidebar_state="auto", menu_items=None)
|
|
|
9 |
st.title("Ask the HUD Audit Guide π¬π€")
|
10 |
st.info("Check out more info on the complete HUD Audit Guide at the official [website](https://www.hudoig.gov/library/single-audit-guidance/hud-consolidated-audit-guide)", icon="π")
|
11 |
+
|
12 |
+
openai_api_key = st.sidebar.text_input('OpenAI API Key', type='password')
|
13 |
+
|
14 |
+
def generate_response(input_text):
|
15 |
+
llm = OpenAI(temperature=0.7, openai_api_key=openai_api_key)
|
16 |
+
st.info(llm(input_text))
|
17 |
+
|
18 |
if "messages" not in st.session_state.keys(): # Initialize the chat messages history
|
19 |
st.session_state.messages = [
|
20 |
{"role": "assistant", "content": "Ask me a question about the HUD Audit Guide - Chapter 6 - Ginnie Mae Issuers of Mortgage-Backed Securities Audit Guidance!"}
|
|
|
34 |
chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
|
35 |
|
36 |
if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
|
37 |
+
if not openai_api_key.startswith('sk-'):
|
38 |
+
st.warning('Please enter your OpenAI API key!', icon='β ')
|
39 |
+
else: # Only allow the user to proceed if it appears they've entered a valid OpenAI API key
|
40 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
41 |
|
42 |
for message in st.session_state.messages: # Display the prior chat messages
|
43 |
with st.chat_message(message["role"]):
|