makhdoomnaeem commited on
Commit
e1410c3
·
verified ·
1 Parent(s): 32532bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -17,12 +17,25 @@ GOOGLE_DRIVE_LINK = "https://drive.google.com/drive/folders/1gVdnV1za1thrVnH4LAL
17
 
18
  # Function to download the PDF from Google Drive
19
  def download_pdf():
20
- file_id = GOOGLE_DRIVE_LINK.split("/d/")[1].split("/view")[0]
21
- url = f"https://drive.google.com/uc?id={1gVdnV1za1thrVnH4LALbDzPtcvKr0z4u}&export=download"
22
- response = requests.get(url)
23
- with open("document.pdf", "wb") as f:
24
- f.write(response.content)
25
- return "document.pdf"
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  # Function to extract text from PDF
28
  def extract_text_from_pdf(pdf_file):
 
17
 
18
  # Function to download the PDF from Google Drive
19
  def download_pdf():
20
+ try:
21
+ if "/d/" in GOOGLE_DRIVE_LINK:
22
+ file_id = GOOGLE_DRIVE_LINK.split("/d/")[1].split("/view")[0]
23
+ elif "id=" in GOOGLE_DRIVE_LINK:
24
+ file_id = GOOGLE_DRIVE_LINK.split("id=")[1].split("&")[0]
25
+ else:
26
+ raise ValueError("Invalid Google Drive link format.")
27
+
28
+ url = f"https://drive.google.com/uc?id={makhdoomnaeem@gmail.com}&export=download"
29
+ response = requests.get(url)
30
+ response.raise_for_status() # Raise an error for bad responses
31
+
32
+ with open("document.pdf", "wb") as f:
33
+ f.write(response.content)
34
+ return "document.pdf"
35
+ except Exception as e:
36
+ st.error(f"Failed to download PDF: {e}")
37
+ return None
38
+
39
 
40
  # Function to extract text from PDF
41
  def extract_text_from_pdf(pdf_file):