Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -196,6 +196,7 @@ def process_pdf(file):
|
|
| 196 |
df = chatbot.paper_df(paper_text)
|
| 197 |
df = chatbot.calculate_embeddings(df)
|
| 198 |
print("Done processing pdf")
|
|
|
|
| 199 |
|
| 200 |
def download_pdf(url):
|
| 201 |
chatbot = Chatbot()
|
|
@@ -207,6 +208,7 @@ def download_pdf(url):
|
|
| 207 |
df = chatbot.paper_df(paper_text)
|
| 208 |
df = chatbot.calculate_embeddings(df)
|
| 209 |
print("Done processing pdf")
|
|
|
|
| 210 |
|
| 211 |
def show_pdf(file_content):
|
| 212 |
base64_pdf = base64.b64encode(file_content).decode('utf-8')
|
|
@@ -217,6 +219,7 @@ def show_pdf(file_content):
|
|
| 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"])
|
|
@@ -226,7 +229,7 @@ def main():
|
|
| 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 |
|
|
@@ -237,7 +240,7 @@ def main():
|
|
| 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:
|
|
@@ -247,7 +250,10 @@ def main():
|
|
| 247 |
query = st.text_input("Enter your query:")
|
| 248 |
if query:
|
| 249 |
if st.button("Get answer"):
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
| 251 |
st.write(response['answer'])
|
| 252 |
st.write("Sources:")
|
| 253 |
for source in response['sources']:
|
|
|
|
| 196 |
df = chatbot.paper_df(paper_text)
|
| 197 |
df = chatbot.calculate_embeddings(df)
|
| 198 |
print("Done processing pdf")
|
| 199 |
+
return chatbot.embeddings
|
| 200 |
|
| 201 |
def download_pdf(url):
|
| 202 |
chatbot = Chatbot()
|
|
|
|
| 208 |
df = chatbot.paper_df(paper_text)
|
| 209 |
df = chatbot.calculate_embeddings(df)
|
| 210 |
print("Done processing pdf")
|
| 211 |
+
return chatbot.embeddings
|
| 212 |
|
| 213 |
def show_pdf(file_content):
|
| 214 |
base64_pdf = base64.b64encode(file_content).decode('utf-8')
|
|
|
|
| 219 |
def main():
|
| 220 |
st.title("Research Paper Guru")
|
| 221 |
st.subheader("Upload PDF or Enter URL")
|
| 222 |
+
embeddings = None
|
| 223 |
col1, col2 = st.columns(2)
|
| 224 |
with col1:
|
| 225 |
pdf_option = st.selectbox("Choose an option:", ["Upload PDF", "Enter URL"])
|
|
|
|
| 229 |
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
| 230 |
if uploaded_file is not None:
|
| 231 |
file_content = uploaded_file.read()
|
| 232 |
+
embeddings = process_pdf(file_content)
|
| 233 |
st.success("PDF uploaded and processed successfully!")
|
| 234 |
show_pdf(file_content)
|
| 235 |
|
|
|
|
| 240 |
try:
|
| 241 |
r = requests.get(str(url))
|
| 242 |
content = r.content
|
| 243 |
+
embeddings = download_pdf(url)
|
| 244 |
st.success("PDF downloaded and processed successfully!")
|
| 245 |
show_pdf(content)
|
| 246 |
except Exception as e:
|
|
|
|
| 250 |
query = st.text_input("Enter your query:")
|
| 251 |
if query:
|
| 252 |
if st.button("Get answer"):
|
| 253 |
+
if embeddings is not None:
|
| 254 |
+
response = chatbot.reply(embeddings, query)
|
| 255 |
+
else:
|
| 256 |
+
st.warning("Please upload a PDF or enter a URL first.")
|
| 257 |
st.write(response['answer'])
|
| 258 |
st.write("Sources:")
|
| 259 |
for source in response['sources']:
|