Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,14 +7,16 @@ from PyPDF2 import PdfReader
|
|
| 7 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 8 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
pdf_text_store = ""
|
| 12 |
|
| 13 |
def extract_text_from_pdf(pdf_file):
|
| 14 |
reader = PdfReader(pdf_file)
|
| 15 |
text = ""
|
| 16 |
for page in reader.pages:
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
return text
|
| 19 |
|
| 20 |
def upload_pdf(file, history):
|
|
@@ -77,6 +79,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"))
|
|
| 77 |
padding: 1em;
|
| 78 |
border-radius: 0.75em;
|
| 79 |
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
|
|
| 80 |
}
|
| 81 |
.chat-area {
|
| 82 |
background: white;
|
|
@@ -92,7 +95,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"))
|
|
| 92 |
|
| 93 |
with gr.Row():
|
| 94 |
with gr.Column(scale=1, min_width=250):
|
| 95 |
-
with gr.
|
| 96 |
gr.Markdown("### π Upload Your PDF")
|
| 97 |
pdf_upload = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 98 |
upload_btn = gr.Button("π Process PDF", elem_classes="custom-btn")
|
|
@@ -103,7 +106,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"))
|
|
| 103 |
show_copy_button=True,
|
| 104 |
elem_classes="chat-area"
|
| 105 |
)
|
| 106 |
-
|
| 107 |
user_input = gr.Textbox(
|
| 108 |
placeholder="Ask something about your PDF...",
|
| 109 |
show_label=False
|
|
|
|
| 7 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 8 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 9 |
|
| 10 |
+
# Global variable to store PDF text
|
| 11 |
pdf_text_store = ""
|
| 12 |
|
| 13 |
def extract_text_from_pdf(pdf_file):
|
| 14 |
reader = PdfReader(pdf_file)
|
| 15 |
text = ""
|
| 16 |
for page in reader.pages:
|
| 17 |
+
page_text = page.extract_text()
|
| 18 |
+
if page_text:
|
| 19 |
+
text += page_text + "\n"
|
| 20 |
return text
|
| 21 |
|
| 22 |
def upload_pdf(file, history):
|
|
|
|
| 79 |
padding: 1em;
|
| 80 |
border-radius: 0.75em;
|
| 81 |
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
| 82 |
+
margin-bottom: 1em;
|
| 83 |
}
|
| 84 |
.chat-area {
|
| 85 |
background: white;
|
|
|
|
| 95 |
|
| 96 |
with gr.Row():
|
| 97 |
with gr.Column(scale=1, min_width=250):
|
| 98 |
+
with gr.Group(elem_classes="upload-box"):
|
| 99 |
gr.Markdown("### π Upload Your PDF")
|
| 100 |
pdf_upload = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 101 |
upload_btn = gr.Button("π Process PDF", elem_classes="custom-btn")
|
|
|
|
| 106 |
show_copy_button=True,
|
| 107 |
elem_classes="chat-area"
|
| 108 |
)
|
|
|
|
| 109 |
user_input = gr.Textbox(
|
| 110 |
placeholder="Ask something about your PDF...",
|
| 111 |
show_label=False
|