Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -124,30 +124,32 @@ def load_chatbot():
|
|
124 |
return load_qa_chain(llm=OpenAI(), chain_type="stuff")
|
125 |
|
126 |
def main():
|
127 |
-
|
128 |
hide_streamlit_style = """
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
135 |
|
136 |
-
|
137 |
# Main content
|
138 |
st.title("Welcome to BinDocs ChatBot! 🤖")
|
139 |
-
|
140 |
-
#
|
141 |
pdf_path = pdf_file_path
|
142 |
if not os.path.exists(pdf_path):
|
143 |
st.error("File not found. Please check the file path.")
|
144 |
return
|
145 |
|
|
|
146 |
if "chat_history" not in st.session_state:
|
147 |
st.session_state['chat_history'] = []
|
148 |
|
|
|
149 |
display_chat_history(st.session_state['chat_history'])
|
150 |
|
|
|
151 |
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
152 |
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
153 |
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
@@ -155,9 +157,11 @@ def main():
|
|
155 |
new_messages_placeholder = st.empty()
|
156 |
|
157 |
if pdf_path is not None:
|
|
|
158 |
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
159 |
|
160 |
-
|
|
|
161 |
query = "Was genau ist ein Belegarzt?"
|
162 |
|
163 |
if st.button("Wofür wird die Alpha-ID verwendet?", key="button2"):
|
@@ -166,12 +170,8 @@ def main():
|
|
166 |
if st.button("Was sind die Vorteile des ambulanten operierens?", key="button3"):
|
167 |
query = "Was sind die Vorteile des ambulanten operierens?"
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
# For default styled buttons, use st.button
|
172 |
-
if st.button("Was sind die Vorteile des ambulanten operierens?"):
|
173 |
-
query = "Was sind die Vorteile des ambulanten operierens?"
|
174 |
-
|
175 |
loading_message = st.empty()
|
176 |
loading_message.text('Bot is thinking...')
|
177 |
|
@@ -197,9 +197,8 @@ def main():
|
|
197 |
# Clear the input field by setting the query variable to an empty string
|
198 |
query = ""
|
199 |
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
|
204 |
|
205 |
def display_chat_history(chat_history):
|
|
|
124 |
return load_qa_chain(llm=OpenAI(), chain_type="stuff")
|
125 |
|
126 |
def main():
|
127 |
+
# Hide Streamlit's menu and footer
|
128 |
hide_streamlit_style = """
|
129 |
+
<style>
|
130 |
+
#MainMenu {visibility: hidden;}
|
131 |
+
footer {visibility: hidden;}
|
132 |
+
</style>
|
133 |
+
"""
|
134 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
135 |
|
|
|
136 |
# Main content
|
137 |
st.title("Welcome to BinDocs ChatBot! 🤖")
|
138 |
+
|
139 |
+
# Check if PDF file exists
|
140 |
pdf_path = pdf_file_path
|
141 |
if not os.path.exists(pdf_path):
|
142 |
st.error("File not found. Please check the file path.")
|
143 |
return
|
144 |
|
145 |
+
# Initialize chat history in session state
|
146 |
if "chat_history" not in st.session_state:
|
147 |
st.session_state['chat_history'] = []
|
148 |
|
149 |
+
# Display previous chat messages
|
150 |
display_chat_history(st.session_state['chat_history'])
|
151 |
|
152 |
+
# Spacer
|
153 |
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
154 |
st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
|
155 |
st.write("<!-- End Spacer -->", unsafe_allow_html=True)
|
|
|
157 |
new_messages_placeholder = st.empty()
|
158 |
|
159 |
if pdf_path is not None:
|
160 |
+
# User input for questions
|
161 |
query = st.text_input("Ask questions about your PDF file (in any preferred language):")
|
162 |
|
163 |
+
# Buttons for predefined queries
|
164 |
+
if st.button("Was genau ist ein Belegarzt?", key="button1"):
|
165 |
query = "Was genau ist ein Belegarzt?"
|
166 |
|
167 |
if st.button("Wofür wird die Alpha-ID verwendet?", key="button2"):
|
|
|
170 |
if st.button("Was sind die Vorteile des ambulanten operierens?", key="button3"):
|
171 |
query = "Was sind die Vorteile des ambulanten operierens?"
|
172 |
|
173 |
+
# Processing the query
|
174 |
+
if query:
|
|
|
|
|
|
|
|
|
175 |
loading_message = st.empty()
|
176 |
loading_message.text('Bot is thinking...')
|
177 |
|
|
|
197 |
# Clear the input field by setting the query variable to an empty string
|
198 |
query = ""
|
199 |
|
200 |
+
# Mark all messages as old after displaying
|
201 |
+
st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
|
|
|
202 |
|
203 |
|
204 |
def display_chat_history(chat_history):
|