Spaces:
Sleeping
Sleeping
DrishtiSharma
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -188,6 +188,35 @@ def extract_patent_number(url):
|
|
188 |
match = re.search(pattern, url)
|
189 |
return match.group(1) if match else None
|
190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
if __name__ == "__main__":
|
192 |
st.set_page_config(
|
193 |
page_title="Patent Chat: Google Patents Chat Demo",
|
|
|
188 |
match = re.search(pattern, url)
|
189 |
return match.group(1) if match else None
|
190 |
|
191 |
+
def preview_pdf(pdf_path, scale_factor=0.5):
|
192 |
+
"""
|
193 |
+
Generate and display a resized preview of the first page of the PDF.
|
194 |
+
Args:
|
195 |
+
pdf_path (str): Path to the PDF file.
|
196 |
+
scale_factor (float): Factor to reduce the image size (default is 0.5).
|
197 |
+
Returns:
|
198 |
+
str: Path to the resized image preview.
|
199 |
+
"""
|
200 |
+
try:
|
201 |
+
# Open the PDF and extract the first page
|
202 |
+
doc = fitz.open(pdf_path)
|
203 |
+
first_page = doc[0]
|
204 |
+
|
205 |
+
# Apply scaling using a transformation matrix
|
206 |
+
matrix = fitz.Matrix(scale_factor, scale_factor) # Scale down the image
|
207 |
+
pix = first_page.get_pixmap(matrix=matrix) # Generate scaled image
|
208 |
+
|
209 |
+
# Save the preview image
|
210 |
+
temp_image_path = os.path.join(tempfile.gettempdir(), "pdf_preview.png")
|
211 |
+
pix.save(temp_image_path)
|
212 |
+
|
213 |
+
doc.close()
|
214 |
+
return temp_image_path
|
215 |
+
|
216 |
+
except Exception as e:
|
217 |
+
st.error(f"Error generating PDF preview: {e}")
|
218 |
+
return None
|
219 |
+
|
220 |
if __name__ == "__main__":
|
221 |
st.set_page_config(
|
222 |
page_title="Patent Chat: Google Patents Chat Demo",
|