Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -152,8 +152,8 @@ class Chatbot():
|
|
152 |
print(sources)
|
153 |
return results.head(n)
|
154 |
|
155 |
-
def create_prompt(self, df, user_input):
|
156 |
-
result = self.search_embeddings(df, user_input, n=3)
|
157 |
print(result)
|
158 |
prompt = """You are a large language model whose expertise is reading and and providing answers about research papers.
|
159 |
You are given a query and a series of text embeddings from a paper in order of their cosine similarity to the query.
|
@@ -216,41 +216,42 @@ def show_pdf(file_content):
|
|
216 |
|
217 |
def main():
|
218 |
st.title("Research Paper Guru")
|
219 |
-
st.subheader("Ask a question about a research paper and get an answer with sources!")
|
220 |
st.subheader("Upload PDF or Enter URL")
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
if pdf_option == "Upload PDF":
|
226 |
-
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
227 |
-
if uploaded_file is not None:
|
228 |
-
file_content = uploaded_file.read()
|
229 |
-
process_pdf(file_content)
|
230 |
-
st.success("PDF uploaded and processed successfully!")
|
231 |
-
show_pdf(file_content)
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
download_pdf(url)
|
241 |
-
st.success("PDF downloaded and processed successfully!")
|
242 |
-
show_pdf(content)
|
243 |
-
except Exception as e:
|
244 |
-
st.error(f"An error occurred while processing the PDF: {e}")
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
if __name__ == "__main__":
|
256 |
main()
|
|
|
152 |
print(sources)
|
153 |
return results.head(n)
|
154 |
|
155 |
+
def create_prompt(self, embeddings, df, user_input):
|
156 |
+
result = self.search_embeddings(df, embeddings, user_input, n=3)
|
157 |
print(result)
|
158 |
prompt = """You are a large language model whose expertise is reading and and providing answers about research papers.
|
159 |
You are given a query and a series of text embeddings from a paper in order of their cosine similarity to the query.
|
|
|
216 |
|
217 |
def main():
|
218 |
st.title("Research Paper Guru")
|
|
|
219 |
st.subheader("Upload PDF or Enter URL")
|
220 |
+
col1, col2 = st.columns(2)
|
221 |
+
with col1:
|
222 |
+
pdf_option = st.selectbox("Choose an option:", ["Upload PDF", "Enter URL"])
|
223 |
+
chatbot = Chatbot()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
+
if pdf_option == "Upload PDF":
|
226 |
+
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
227 |
+
if uploaded_file is not None:
|
228 |
+
file_content = uploaded_file.read()
|
229 |
+
process_pdf(file_content)
|
230 |
+
st.success("PDF uploaded and processed successfully!")
|
231 |
+
show_pdf(file_content)
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
+
elif pdf_option == "Enter URL":
|
234 |
+
url = st.text_input("Enter the URL of the PDF:")
|
235 |
+
if url:
|
236 |
+
if st.button("Download and process PDF"):
|
237 |
+
try:
|
238 |
+
r = requests.get(str(url))
|
239 |
+
content = r.content
|
240 |
+
download_pdf(url)
|
241 |
+
st.success("PDF downloaded and processed successfully!")
|
242 |
+
show_pdf(content)
|
243 |
+
except Exception as e:
|
244 |
+
st.error(f"An error occurred while processing the PDF: {e}")
|
245 |
+
with col2:
|
246 |
+
st.subheader("Ask a question about a research paper and get an answer with sources!")
|
247 |
+
query = st.text_input("Enter your query:")
|
248 |
+
if query:
|
249 |
+
if st.button("Get answer"):
|
250 |
+
response = chatbot.reply(query)
|
251 |
+
st.write(response['answer'])
|
252 |
+
st.write("Sources:")
|
253 |
+
for source in response['sources']:
|
254 |
+
st.write(source)
|
255 |
|
256 |
if __name__ == "__main__":
|
257 |
main()
|