Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -221,41 +221,41 @@ def main():
|
|
| 221 |
st.title("Research Paper Guru")
|
| 222 |
st.subheader("Upload PDF or Enter URL")
|
| 223 |
embeddings = None
|
| 224 |
-
|
| 225 |
-
|
| 226 |
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
|
| 260 |
if __name__ == "__main__":
|
| 261 |
main()
|
|
|
|
| 221 |
st.title("Research Paper Guru")
|
| 222 |
st.subheader("Upload PDF or Enter URL")
|
| 223 |
embeddings = None
|
| 224 |
+
pdf_option = st.selectbox("Choose an option:", ["Upload PDF", "Enter URL"])
|
| 225 |
+
chatbot = Chatbot()
|
| 226 |
|
| 227 |
+
if pdf_option == "Upload PDF":
|
| 228 |
+
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
| 229 |
+
if uploaded_file is not None:
|
| 230 |
+
file_content = uploaded_file.read()
|
| 231 |
+
embeddings = process_pdf(file_content)
|
| 232 |
+
st.success("PDF uploaded and processed successfully!")
|
| 233 |
+
show_pdf(file_content)
|
| 234 |
|
| 235 |
+
elif pdf_option == "Enter URL":
|
| 236 |
+
url = st.text_input("Enter the URL of the PDF:")
|
| 237 |
+
if url:
|
| 238 |
+
if st.button("Download and process PDF"):
|
| 239 |
+
try:
|
| 240 |
+
r = requests.get(str(url))
|
| 241 |
+
content = r.content
|
| 242 |
+
embeddings = download_pdf(url)
|
| 243 |
+
st.success("PDF downloaded and processed successfully!")
|
| 244 |
+
show_pdf(content)
|
| 245 |
+
except Exception as e:
|
| 246 |
+
st.error(f"An error occurred while processing the PDF: {e}")
|
| 247 |
+
st.subheader("Ask a question about a research paper and get an answer with sources!")
|
| 248 |
+
query = st.text_input("Enter your query:")
|
| 249 |
+
if query:
|
| 250 |
+
if st.button("Get answer"):
|
| 251 |
+
if embeddings is not None:
|
| 252 |
+
response = chatbot.reply(embeddings, query)
|
| 253 |
+
else:
|
| 254 |
+
st.warning("Please upload a PDF or enter a URL first.")
|
| 255 |
+
st.write(response['answer'])
|
| 256 |
+
st.write("Sources:")
|
| 257 |
+
for source in response['sources']:
|
| 258 |
+
st.write(source)
|
| 259 |
|
| 260 |
if __name__ == "__main__":
|
| 261 |
main()
|