Spaces:
Sleeping
Sleeping
Refactor app
Browse files
app.py
CHANGED
@@ -66,7 +66,7 @@ def main():
|
|
66 |
The main function that runs the Streamlit app.
|
67 |
"""
|
68 |
|
69 |
-
assistant_message = "Hello, you can upload a document and chat with me to ask questions related to its content."
|
70 |
st.session_state["messages"] = [
|
71 |
Assistant(message=assistant_message).build_message()
|
72 |
]
|
@@ -142,22 +142,25 @@ def build_sidebar():
|
|
142 |
with st.sidebar:
|
143 |
st.title("π InkChatGPT")
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
)
|
151 |
|
152 |
-
|
153 |
-
if not openai_api_key:
|
154 |
-
st.info("Please add your OpenAI API key to continue.")
|
155 |
|
|
|
|
|
|
|
156 |
uploaded_file = st.file_uploader(
|
157 |
"Select a file", type=["pdf", "docx", "txt"], key="file_uploader"
|
158 |
)
|
159 |
|
160 |
-
add_file = st.
|
|
|
|
|
|
|
161 |
if add_file and uploaded_file and openai_api_key.startswith("sk-"):
|
162 |
with st.spinner("π Thinking..."):
|
163 |
vector_store = load_and_process_file(uploaded_file)
|
@@ -165,7 +168,7 @@ def build_sidebar():
|
|
165 |
if vector_store:
|
166 |
crc = initialize_chat_model(vector_store)
|
167 |
st.session_state.crc = crc
|
168 |
-
st.
|
169 |
f"File: `{uploaded_file.name}`, processed successfully!"
|
170 |
)
|
171 |
|
|
|
66 |
The main function that runs the Streamlit app.
|
67 |
"""
|
68 |
|
69 |
+
assistant_message = "Hello, you can upload a document and chat with me to ask questions related to its content. Start by adding OpenAI API Key in the sidebar."
|
70 |
st.session_state["messages"] = [
|
71 |
Assistant(message=assistant_message).build_message()
|
72 |
]
|
|
|
142 |
with st.sidebar:
|
143 |
st.title("π InkChatGPT")
|
144 |
|
145 |
+
openai_api_key = st.text_input(
|
146 |
+
"OpenAI API Key",
|
147 |
+
type="password",
|
148 |
+
placeholder="Enter your OpenAI API key",
|
149 |
+
)
|
|
|
150 |
|
151 |
+
st.session_state.api_key = openai_api_key
|
|
|
|
|
152 |
|
153 |
+
if not openai_api_key:
|
154 |
+
st.info("Please add your OpenAI API key to continue.")
|
155 |
+
else:
|
156 |
uploaded_file = st.file_uploader(
|
157 |
"Select a file", type=["pdf", "docx", "txt"], key="file_uploader"
|
158 |
)
|
159 |
|
160 |
+
add_file = st.button(
|
161 |
+
"Process File",
|
162 |
+
disabled=(not uploaded_file and not openai_api_key),
|
163 |
+
)
|
164 |
if add_file and uploaded_file and openai_api_key.startswith("sk-"):
|
165 |
with st.spinner("π Thinking..."):
|
166 |
vector_store = load_and_process_file(uploaded_file)
|
|
|
168 |
if vector_store:
|
169 |
crc = initialize_chat_model(vector_store)
|
170 |
st.session_state.crc = crc
|
171 |
+
st.chat_message(ChatProfileRoleEnum.Assistant).write(
|
172 |
f"File: `{uploaded_file.name}`, processed successfully!"
|
173 |
)
|
174 |
|