Spaces:
Sleeping
Sleeping
DrishtiSharma
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -158,6 +158,7 @@ if __name__ == "__main__":
|
|
158 |
|
159 |
st.write(f"Patent number: **{patent_number}**")
|
160 |
|
|
|
161 |
pdf_path = os.path.join(tempfile.gettempdir(), f"{patent_number}.pdf")
|
162 |
if os.path.isfile(pdf_path):
|
163 |
st.write("✅ File already downloaded.")
|
@@ -166,6 +167,18 @@ if __name__ == "__main__":
|
|
166 |
pdf_path = download_pdf(patent_number)
|
167 |
st.write(f"✅ File downloaded: {pdf_path}")
|
168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
st.write("🔄 Loading document into the system...")
|
170 |
|
171 |
# Persist the chain in session state to prevent reloading
|
@@ -185,12 +198,15 @@ if __name__ == "__main__":
|
|
185 |
with st.chat_message(message["role"]):
|
186 |
st.markdown(message["content"])
|
187 |
|
|
|
188 |
if "chain" in st.session_state:
|
189 |
if user_input := st.chat_input("What is your question?"):
|
|
|
190 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
191 |
with st.chat_message("user"):
|
192 |
st.markdown(user_input)
|
193 |
|
|
|
194 |
with st.chat_message("assistant"):
|
195 |
message_placeholder = st.empty()
|
196 |
full_response = ""
|
@@ -202,7 +218,8 @@ if __name__ == "__main__":
|
|
202 |
except Exception as e:
|
203 |
full_response = f"An error occurred: {e}"
|
204 |
|
|
|
205 |
message_placeholder.markdown(full_response)
|
206 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
207 |
else:
|
208 |
-
st.info("Press the 'Load and Process Patent' button to start processing.")
|
|
|
158 |
|
159 |
st.write(f"Patent number: **{patent_number}**")
|
160 |
|
161 |
+
# Define PDF path in temp directory
|
162 |
pdf_path = os.path.join(tempfile.gettempdir(), f"{patent_number}.pdf")
|
163 |
if os.path.isfile(pdf_path):
|
164 |
st.write("✅ File already downloaded.")
|
|
|
167 |
pdf_path = download_pdf(patent_number)
|
168 |
st.write(f"✅ File downloaded: {pdf_path}")
|
169 |
|
170 |
+
# Display a preview of the downloaded PDF
|
171 |
+
st.write("📄 Preview of the downloaded patent PDF:")
|
172 |
+
if os.path.isfile(pdf_path):
|
173 |
+
with open(pdf_path, "rb") as pdf_file:
|
174 |
+
st.download_button(
|
175 |
+
label="Download PDF",
|
176 |
+
data=pdf_file,
|
177 |
+
file_name=f"{patent_number}.pdf",
|
178 |
+
mime="application/pdf"
|
179 |
+
)
|
180 |
+
st.pdf(pdf_path)
|
181 |
+
|
182 |
st.write("🔄 Loading document into the system...")
|
183 |
|
184 |
# Persist the chain in session state to prevent reloading
|
|
|
198 |
with st.chat_message(message["role"]):
|
199 |
st.markdown(message["content"])
|
200 |
|
201 |
+
# Chat Input Section
|
202 |
if "chain" in st.session_state:
|
203 |
if user_input := st.chat_input("What is your question?"):
|
204 |
+
# Append user message
|
205 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
206 |
with st.chat_message("user"):
|
207 |
st.markdown(user_input)
|
208 |
|
209 |
+
# Generate assistant response
|
210 |
with st.chat_message("assistant"):
|
211 |
message_placeholder = st.empty()
|
212 |
full_response = ""
|
|
|
218 |
except Exception as e:
|
219 |
full_response = f"An error occurred: {e}"
|
220 |
|
221 |
+
# Display assistant response
|
222 |
message_placeholder.markdown(full_response)
|
223 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
224 |
else:
|
225 |
+
st.info("Press the 'Load and Process Patent' button to start processing.")
|