Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -97,10 +97,8 @@ def retrieve_context(query, k=3):
|
|
97 |
|
98 |
# Main application layout
|
99 |
if 'DEEPSEEK_API_KEY' in st.session_state:
|
100 |
-
# Create a
|
101 |
-
|
102 |
-
|
103 |
-
with col2:
|
104 |
st.header("Document Upload")
|
105 |
uploaded_files = st.file_uploader(
|
106 |
"Upload your documents",
|
@@ -128,17 +126,37 @@ if 'DEEPSEEK_API_KEY' in st.session_state:
|
|
128 |
if st.button("Clear Knowledge Base"):
|
129 |
st.session_state.vectorstore = None
|
130 |
st.success("Knowledge base cleared!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
-
|
|
|
|
|
133 |
# Display chat history
|
134 |
for message in st.session_state.chat_history:
|
135 |
with st.chat_message(message["role"]):
|
136 |
st.write(message["content"])
|
137 |
|
138 |
-
#
|
|
|
139 |
user_input = st.chat_input("Type your message here...")
|
140 |
|
141 |
-
if
|
|
|
142 |
# Add user message to chat history
|
143 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
144 |
|
@@ -176,22 +194,4 @@ if user_input:
|
|
176 |
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
177 |
|
178 |
except Exception as e:
|
179 |
-
st.error(f"Error: {str(e)}")
|
180 |
-
|
181 |
-
# Sidebar with info
|
182 |
-
with st.sidebar:
|
183 |
-
st.header("About")
|
184 |
-
st.markdown("""
|
185 |
-
This RAG chatbot uses:
|
186 |
-
- π¦ LangChain for memory and document processing
|
187 |
-
- π FAISS for vector storage and retrieval
|
188 |
-
- π§ HuggingFace for lightweight embeddings (paraphrase-MiniLM-L3-v2)
|
189 |
-
- π€ DeepSeek API for AI responses
|
190 |
-
- π₯οΈ Streamlit for the web interface
|
191 |
-
|
192 |
-
The chatbot can:
|
193 |
-
- Upload and process PDF and text documents
|
194 |
-
- Retrieve relevant information from documents
|
195 |
-
- Generate informed responses using your documents
|
196 |
-
- Maintain conversation context
|
197 |
-
""")
|
|
|
97 |
|
98 |
# Main application layout
|
99 |
if 'DEEPSEEK_API_KEY' in st.session_state:
|
100 |
+
# Create a sidebar for document upload and settings
|
101 |
+
with st.sidebar:
|
|
|
|
|
102 |
st.header("Document Upload")
|
103 |
uploaded_files = st.file_uploader(
|
104 |
"Upload your documents",
|
|
|
126 |
if st.button("Clear Knowledge Base"):
|
127 |
st.session_state.vectorstore = None
|
128 |
st.success("Knowledge base cleared!")
|
129 |
+
|
130 |
+
st.header("About")
|
131 |
+
st.markdown("""
|
132 |
+
This RAG chatbot uses:
|
133 |
+
- π¦ LangChain for memory and document processing
|
134 |
+
- π FAISS for vector storage and retrieval
|
135 |
+
- π§ HuggingFace for lightweight embeddings (paraphrase-MiniLM-L3-v2)
|
136 |
+
- π€ DeepSeek API for AI responses
|
137 |
+
- π₯οΈ Streamlit for the web interface
|
138 |
+
|
139 |
+
The chatbot can:
|
140 |
+
- Upload and process PDF and text documents
|
141 |
+
- Retrieve relevant information from documents
|
142 |
+
- Generate informed responses using your documents
|
143 |
+
- Maintain conversation context
|
144 |
+
""")
|
145 |
|
146 |
+
# Main chat area - create a container for the chat history
|
147 |
+
chat_container = st.container()
|
148 |
+
with chat_container:
|
149 |
# Display chat history
|
150 |
for message in st.session_state.chat_history:
|
151 |
with st.chat_message(message["role"]):
|
152 |
st.write(message["content"])
|
153 |
|
154 |
+
# IMPORTANT: Place chat_input outside of any container and if block
|
155 |
+
# This must be at the main page level
|
156 |
user_input = st.chat_input("Type your message here...")
|
157 |
|
158 |
+
# Handle user input - but only process if API key is available
|
159 |
+
if user_input and 'DEEPSEEK_API_KEY' in st.session_state:
|
160 |
# Add user message to chat history
|
161 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
162 |
|
|
|
194 |
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
195 |
|
196 |
except Exception as e:
|
197 |
+
st.error(f"Error: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|