Spaces:
Runtime error
Runtime error
adnaniqbal001
commited on
Commit
•
6c72794
1
Parent(s):
c07449b
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,28 @@ import PyPDF2
|
|
3 |
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
import torch
|
|
|
6 |
|
7 |
-
# Step 1: Ask for PDF file
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Step 2: Extract text from the PDF
|
11 |
def extract_text_from_pdf(file_path):
|
|
|
3 |
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
import torch
|
6 |
+
from tkinter import Tk, filedialog
|
7 |
|
8 |
+
# Step 1: Ask for the PDF file via file upload dialog
|
9 |
+
def upload_file():
|
10 |
+
"""Open a file dialog to select a PDF file."""
|
11 |
+
root = Tk()
|
12 |
+
root.withdraw() # Hide the root window
|
13 |
+
file_path = filedialog.askopenfilename(
|
14 |
+
title="Select PDF File",
|
15 |
+
filetypes=[("PDF Files", "*.pdf")],
|
16 |
+
)
|
17 |
+
if not file_path:
|
18 |
+
raise ValueError("No file was selected. Please upload a PDF.")
|
19 |
+
return file_path
|
20 |
+
|
21 |
+
print("Please select the PDF file containing the chapter.")
|
22 |
+
try:
|
23 |
+
file_path = upload_file()
|
24 |
+
print(f"File selected: {file_path}")
|
25 |
+
except Exception as e:
|
26 |
+
print(f"Error: {e}")
|
27 |
+
exit()
|
28 |
|
29 |
# Step 2: Extract text from the PDF
|
30 |
def extract_text_from_pdf(file_path):
|