asitts commited on
Commit
5252e57
β€’
1 Parent(s): 18cf9cf

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -56
app.py DELETED
@@ -1,56 +0,0 @@
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
- import os
7
-
8
- st.set_page_config(page_title="SmartStarts", page_icon="πŸ€–", layout="centered", initial_sidebar_state="auto", menu_items=None)
9
-
10
- test_key_print = os.environ['OPENAI_KEY']
11
-
12
- openai.api_key = test_key_print
13
- st.title("SmartStarts Interview πŸ’¬πŸ€–")
14
- st.info("Do not enter any none public info. This is for internal test / demo purposes only.", icon="πŸ“ƒ")
15
-
16
- if "messages" not in st.session_state.keys(): # Initialize the chat messages history
17
- st.session_state.messages = [
18
- {"role": "assistant", "content": "Which SmartStart would you like to provide information for"}
19
- ]
20
-
21
- @st.cache_resource(show_spinner=False)
22
- def load_data():
23
- with st.spinner(text="Loading and indexing the HUD Audit Guide – hang tight! This should take 1-2 minutes."):
24
- reader = SimpleDirectoryReader(input_dir="./data", recursive=True)
25
- docs = reader.load_data()
26
- service_context = ServiceContext.from_defaults(llm=OpenAI(model="gpt-3.5-turbo", temperature=0.5, system_prompt="You are an expert on soliciting information on how assets, called SmartStarts, could be utilized to deliver professional services more efficiently and effectively. You may ask up to 5 quesitons, one at a time, to refine your understanding of how the SmartStart can be leveraged by consulting project teams. Assume that all questions are related to the SmartStart called Scribe. Keep your answers technical and based on facts – do not hallucinate features."))
27
- index = VectorStoreIndex.from_documents(docs, service_context=service_context)
28
- return index
29
-
30
- index = load_data()
31
- #chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True, system_prompt="You are an expert on the Streamlit Python library and your job is to answer technical questions. Assume that all questions are related to the Streamlit Python library. Keep your answers technical and based on facts – do not hallucinate features.")
32
- chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
33
-
34
- if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
35
- st.session_state.messages.append({"role": "user", "content": prompt})
36
-
37
- for message in st.session_state.messages: # Display the prior chat messages
38
- with st.chat_message(message["role"]):
39
- st.write(message["content"])
40
-
41
- if st.session_state.messages[int(index)] == 0:
42
- with st.chat_message("assistant"):
43
- with st.spinner("Warming Up..."):
44
- response = chat_engine.chat("Provide a summary of Scribe. End your response by asking me if anything you've stated is incorrect. Then proceed with asking your series of up to 5 clarifying questions.")
45
- st.write(response.response)
46
- message = {"role": "assistant", "content": response.response}
47
- st.session_state.messages.append(message)
48
-
49
- # If last message is not from assistant, generate a new response
50
- if st.session_state.messages[-1]["role"] != "assistant":
51
- with st.chat_message("assistant"):
52
- with st.spinner("Thinking..."):
53
- response = chat_engine.chat(prompt)
54
- st.write(response.response)
55
- message = {"role": "assistant", "content": response.response}
56
- st.session_state.messages.append(message) # Add response to message history