DrishtiSharma commited on
Commit
5c59c17
·
verified ·
1 Parent(s): 984a863

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # to-do: Enable downloading multiple patent PDFs via corresponding links
2
  import sys
3
  import os
4
  import re
@@ -8,6 +7,7 @@ import streamlit as st
8
  import nltk
9
  import tempfile
10
  import subprocess
 
11
 
12
  # Pin NLTK to version 3.9.1
13
  REQUIRED_NLTK_VERSION = "3.9.1"
@@ -129,6 +129,15 @@ def download_pdf(patent_number):
129
  st.error(f"Failed to download patent PDF: {e}")
130
  st.stop()
131
 
 
 
 
 
 
 
 
 
 
132
  if __name__ == "__main__":
133
  st.set_page_config(
134
  page_title="Patent Chat: Google Patents Chat Demo",
@@ -177,12 +186,10 @@ if __name__ == "__main__":
177
  file_name=f"{patent_number}.pdf",
178
  mime="application/pdf"
179
  )
180
- # Embed PDF using iframe
181
  st.write("📋 PDF Content:")
182
- pdf_display = f"""
183
- <iframe src="file://{pdf_path}" width="700" height="1000" style="border: none;"></iframe>
184
- """
185
- st.components.v1.html(pdf_display, height=1000)
186
 
187
  st.write("🔄 Loading document into the system...")
188
 
 
 
1
  import sys
2
  import os
3
  import re
 
7
  import nltk
8
  import tempfile
9
  import subprocess
10
+ import base64 # For embedding PDF content
11
 
12
  # Pin NLTK to version 3.9.1
13
  REQUIRED_NLTK_VERSION = "3.9.1"
 
129
  st.error(f"Failed to download patent PDF: {e}")
130
  st.stop()
131
 
132
+ def embed_pdf(file_path):
133
+ """Convert PDF file to base64 and embed it in an iframe."""
134
+ with open(file_path, "rb") as f:
135
+ base64_pdf = base64.b64encode(f.read()).decode("utf-8")
136
+ pdf_display = f"""
137
+ <iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" style="border: none;"></iframe>
138
+ """
139
+ return pdf_display
140
+
141
  if __name__ == "__main__":
142
  st.set_page_config(
143
  page_title="Patent Chat: Google Patents Chat Demo",
 
186
  file_name=f"{patent_number}.pdf",
187
  mime="application/pdf"
188
  )
189
+ # Embed PDF content using base64
190
  st.write("📋 PDF Content:")
191
+ pdf_view = embed_pdf(pdf_path)
192
+ st.components.v1.html(pdf_view, height=1000)
 
 
193
 
194
  st.write("🔄 Loading document into the system...")
195